【问题标题】:How to set background color of StackPane node to transparent using javafx/css and fxml如何使用 javafx/css 和 fxml 将 StackPane 节点的背景颜色设置为透明
【发布时间】:2016-12-07 13:18:58
【问题描述】:

尝试为我的BorderPane 创建阴影。我需要使用StackPane 为阴影留出空间。问题是我似乎无法将StackPane 的背景设置为透明。我正在为我的primiaryStage 使用透明样式。

还有其他使用 javaFX 的示例,但我在使用 fxml 时无法弄清楚。

.StackPane{
  -fx-background-color: transparent;
}

这仍然在我的 BorderPane 后面显示白色背景

public class Main extends Application {


    public static Stage Window;

    @Override
    public void start(Stage primaryStage) throws IOException{
        Main.Window = primaryStage;
        Window.initStyle(StageStyle.TRANSPARENT);
        Window.setResizable(false);
        FXMLLoader loader = new FXMLLoader(getClass().getResource("Homepage.fxml"));
        Parent root = loader.load();    
        Window.setScene(new Scene(root));
        root.getStylesheets().add(getClass().getResource("main.css").toExternalForm());

        Window.show();
    }

【问题讨论】:

标签: java css javafx scenebuilder


【解决方案1】:

我发现当使用滚动窗格时,它会在运行时在其下动态创建堆栈窗格。使用风景视图,我可以看到样式类名称为“viewport”,并且可以通过这种方式更改背景颜色。

【讨论】:

    【解决方案2】:

    设置窗口样式可能不起作用,因为您正在使用的操作系统不支持该样式。文档对此进行了说明:

    在某些平台上,装饰可能不可用。

    但对于堆栈窗格的解决方法,您应该提供一个示例图像来说明您的目标。现在还不清楚你到底想要完成什么。

    【讨论】:

    • 使用 Windows 7
    • 已将 img 添加到帖子中
    猜你喜欢
    • 2020-03-03
    • 1970-01-01
    • 1970-01-01
    • 2012-06-26
    • 2016-11-06
    • 1970-01-01
    • 2011-04-14
    • 2014-06-11
    • 2013-01-11
    相关资源
    最近更新 更多