Transparent javafx window background with decorations

I find it difficult to understand how to make a transparent background for the application window in javafx. scene.setFill(null)only works with stage.initStyle(StageStyle.TRANSPARENT). Doc for setFillsays

Both values โ€‹โ€‹of zero mean paint without a background and Paint with transparency, but what is painted behind it will depend on the platform.

but that doesn't make sense to me. It works (on windows 8) only with StageStyle.TRANSPARENTwhich removes the exit button and the one that I still want.

I looked through http://www.adam-bien.com/roller/abien/entry/completely_transparent_windows_stage_in and a few questions here.

Can this be done on windows?

+3
source share
2 answers

, :

  @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();
}

... css

.root {
    -fx-background-color: rgba(0,0,0,0.5); 
}
+1

. JavaFx (CustomStage). , CustomStage Wiki

  • (, /, )
  • .
  • .
0

Source: https://habr.com/ru/post/1618211/


All Articles