javafx transparent window background with decorations

后端 未结 2 408
暗喜
暗喜 2020-12-18 11:00

I\'m having a hard time figuring out how to make a transparent background for an application window in javafx. scene.setFill(null) seems to only work with

相关标签:
2条回答
  • 2020-12-18 11:32

    I've been tinkering with similar settings, and this works for me:

      @Override
       public void start(Stage primaryStage) throws Exception{
          Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
    
          primaryStage.setTitle("Hello World");
          primaryStage.initStyle(StageStyle.TRANSPARENT);
          primaryStage.setOpacity(0.5);
          primaryStage.setFullScreen(true);
          Scene scene = new Scene(root, 300, 275);
          primaryStage.setScene(scene);
          scene.getStylesheets().add(Main.class.getResource("main.css")
                .toExternalForm());
          primaryStage.show();
    }
    

    ...and the css

    .root {
        -fx-background-color: rgba(0,0,0,0.5); 
    }
    
    0 讨论(0)
  • 2020-12-18 11:32

    You can use this library. It is a fully customizable JavaFx Stage (CustomStage). You can see in-detail description of how to use it in this CustomStage Wiki

    It has,

    • Window resizing
    • Default action buttons and their behaviour (close, maximize/restore, minimize)
    • Window dragging
    • Window is automatically scaled as for screen resolution
    • Very responsive
    • Stylable
    • Can achieve transparency
    • Has in-built navigation panes and drawers
    • etc.
    0 讨论(0)
提交回复
热议问题