javafx transparent window background with decorations

青春壹個敷衍的年華 提交于 2019-12-29 07:12:10

问题


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?


回答1:


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



回答2:


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.


来源:https://stackoverflow.com/questions/23576796/javafx-transparent-window-background-with-decorations

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!