【问题标题】:How to place an image into stage as background? [duplicate]如何将图像放入舞台作为背景? [复制]
【发布时间】:2013-06-20 01:44:17
【问题描述】:

有没有办法将图像作为舞台背景而不是先添加到 ImageView 中?

        ImageView splash = new ImageView(getClass().getResource("/splash.png").toExternalForm());
        VBox splashLayout = new VBox();
        splashLayout.getChildren().addAll(splash, progressText, loadProgress);
        Scene splashScene = new Scene(splashLayout);
        initStage.setScene(splashScene);

【问题讨论】:

    标签: javafx-2 javafx


    【解决方案1】:

    为此,您必须在 JavaFx 中使用 CSS,

    这是 CSS 的代码

    .root{
        -fx-background-image: url("your_image.jpg");
    }
    

    并将这个 css 文件添加到您的场景中,

    scene.getStylesheets().add(getClass().getResource("myCss.css").toExternalForm());
    

    【讨论】:

      猜你喜欢
      • 2020-04-17
      • 1970-01-01
      • 1970-01-01
      • 2021-07-12
      • 1970-01-01
      • 2020-07-02
      • 2017-10-02
      • 2014-01-03
      • 2022-01-25
      相关资源
      最近更新 更多