与装饰的javafx透明窗口背景 [英] javafx transparent window background with decorations
问题描述
我很难弄清楚如何在javafx中为应用程序窗口创建透明背景。 scene.setFill(null)
似乎只适用于 stage.initStyle(StageStyle.TRANSPARENT)
。文档 setFill
说
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.
但这对我没有意义。它只在 StageStyle.TRANSPARENT
中工作(在Windows 8上),它会删除退出按钮以及我仍然需要的按钮。
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.
我看过 http://www.adam-bien.com/ roller / abien / entry / fully_transparent_windows_stage_in 和这里的几个问题。
I've looked at http://www.adam-bien.com/roller/abien/entry/completely_transparent_windows_stage_in and a few questions here.
这可以在Windows上完成吗?
Can this be done on windows?
推荐答案
我一直在修改类似的设置,这对我有用:
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();
}
...和css
.root {
-fx-background-color: rgba(0,0,0,0.5);
}
这篇关于与装饰的javafx透明窗口背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!