Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
483 views
in Technique[技术] by (71.8m points)

java - javafx transparent window background with decorations

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 stage.initStyle(StageStyle.TRANSPARENT). Doc for setFill says

Both a null value meaning paint no background and a Paint with transparency are supported, 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.TRANSPARENT which removes the exit button and such which I still want.

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

Can this be done on windows?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...