BorderPane javafx的背景

BorderPane javafx的背景,java,css,javafx,background,Java,Css,Javafx,Background,我制作了一个UI舞台。 我在舞台上有一个边框窗格。 现在,我想在layout 我想使用CSS,但它不起作用 public void start(Stage primaryStage) throws Exception { carStage = new Stage(); BorderPane layout = new BorderPane(); carScene = new Scene(layout); carStage.setTitle("רכב");

我制作了一个UI舞台。 我在舞台上有一个
边框窗格
。 现在,我想在
layout

我想使用CSS,但它不起作用

    public void start(Stage primaryStage) throws Exception {
    carStage = new Stage();
    BorderPane layout = new BorderPane();
    carScene = new Scene(layout);
    carStage.setTitle("רכב");
    GridPane center = new GridPane();
    enterFieldsToCenter(center);
    right(layout);
    layout.setCenter(center);
    layout.setStyle("style.css");
    carStage.setScene(carScene);
    layout.getCenter().setStyle("-fx-background-image: url(\"C:\\Users\\itayz\\eclipse-workspace\\Itay'sCar\\src\\CrystalClear.jpg\");"
            + "-fx-background-size: 500, 500;"
            + "-fx-background-repeat: no-repeat;");

    sizeOfStage();
    carStage.show();

}
背景来自: 我怎样才能轻松导入它


注意:文件存在于路径中。问题是您的URI没有方案

至:

url([\“\']?[\“\']?)

可以是绝对URI,例如:

  • url(http://example.com)

  • url('http://example.com)

  • url(“http://example.com“”

或者它可以是相对于CSS文件的位置

因此,您必须在scheme中使用绝对URL:

layout.getCenter().setStyle("-fx-background-image: url(\"file:///C:/Users/itayz/eclipse-workspace/Itay'sCar/src/CrystalClear.jpg\");"
        + "-fx-background-size: 500, 500;"
        + "-fx-background-repeat: no-repeat;");

除此之外,我建议使用相对URL并将图像放置在项目资源中。

问题在于您的URI没有方案

至:

url([\“\']?[\“\']?)

可以是绝对URI,例如:

  • url(http://example.com)

  • url('http://example.com)

  • url(“http://example.com“”

或者它可以是相对于CSS文件的位置

因此,您必须在scheme中使用绝对URL:

layout.getCenter().setStyle("-fx-background-image: url(\"file:///C:/Users/itayz/eclipse-workspace/Itay'sCar/src/CrystalClear.jpg\");"
        + "-fx-background-size: 500, 500;"
        + "-fx-background-repeat: no-repeat;");

除此之外,我建议使用相对URL并将图像放置在您的项目资源中。

这种模式对我很有效:

-fx-background-image: url('file:C:/Data/example.jpg');
因此,在您的情况下,它将是:

layout.getCenter().setStyle("-fx-background-image: url('file:C:/Users/itayz/eclipse-workspace/Itay'sCar/src/CrystalClear.jpg');"
                                    + "-fx-background-size: 500, 500;"
                                    + "-fx-background-repeat: no-repeat;");

这种模式适合我:

-fx-background-image: url('file:C:/Data/example.jpg');
因此,在您的情况下,它将是:

layout.getCenter().setStyle("-fx-background-image: url('file:C:/Users/itayz/eclipse-workspace/Itay'sCar/src/CrystalClear.jpg');"
                                    + "-fx-background-size: 500, 500;"
                                    + "-fx-background-repeat: no-repeat;");

你可以试试
url(“/CrystalClear.jpg”)(请参阅)。但是为什么不使用a来设置链接到的颜色的背景(也可以这样做)?您可以尝试
url(“/CrystalClear.jpg”)(请参阅)。但是为什么不使用a来设置链接到的颜色的背景(也可以这样做)?我更新了我的问题,似乎我忘记了a
/
。您能再试一次吗?错误:2019年3月18日11:04:59 PM com.sun.javafx.css.StyleManager getCachedImage警告:加载图像:文件时出错:/C:Usersitayzeclipse-workspaceItay'scarscrystalclear。jpg@ItayZemah您是否可以尝试使用
/
而不是
\
作为文件分隔符。正如我在回答中所显示的那样?我更新了我的问题,似乎我忘记了一个
/
。您能再试一次吗?错误:2019年3月18日11:04:59 PM com.sun.javafx.css.StyleManager getCachedImage警告:加载图像:文件时出错:/C:Usersitayzeclipse-workspaceItay'scarscrystalclear。jpg@ItayZemah您是否可以尝试使用
/
而不是
\
作为文件分隔符。如我在回答中所示?2019年3月20日上午11:38:24 com.sun.javafx.css.parser.CSSParser术语警告:css错误解析'*{-fx背景图像:url('file:C:/Users/itayz/eclipse workspace/Itay'sCar/src/CrystalClear.jpg');-fx背景大小:500500;-fx背景重复:无重复;}:意外标记'file:C:/Users/itayz/eclipse workspace/Itay'位于[1,24],它可能与您的路径有关。我想撇号就是问题所在。你很可能必须避开它(\')。2019年3月20日上午11:38:24 com.sun.javafx.css.parser.CSSParser术语警告:css错误解析'*{-fx背景图像:url('file:C:/Users/itayz/eclipse workspace/Itay'sCar/src/CrystalClear.jpg');-fx背景大小:500500;-fx背景重复:无重复;}:意外标记'file:C:/Users/itayz/eclipse workspace/Itay'位于[1,24],它可能与您的路径有关。我想撇号就是问题所在。你很可能不得不逃避它(\')。