[英]background to BorderPane javafx
I made a UI stage. 我进入了UI阶段。 and I have a
BorderPane
in the stage. 我在舞台上有一个
BorderPane
。 now, I want to add a bacgGround Image to layout
现在,我想向
layout
添加一个bacgGround图像
I want to use CSS but it doesn't work 我想使用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();
}
the background is from : https://uigradients.com/#CrystalClear how can I import it easily? 背景来自: https : //uigradients.com/#CrystalClear如何轻松导入?
Note: the file exist in the path 注意:该文件存在于路径中
The Problem is that your URI has no scheme. 问题是您的URI没有方案。
url ( [\\"\\']? <address> [\\"\\']? )
<address>
can be an absolute URI, for example:<address>
可以是绝对URI,例如:
url(http://example.com)
url('http://example.com')
url("http://example.com")
or it can be relative to the location of the CSS file.
或者可以相对于CSS文件的位置。
So you have to use an absolute URL with 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;");
Beside that I would recommend to use a relative URL and place the image in your project resources. 除此之外,我建议使用相对URL并将图像放置在您的项目资源中。
This pattern worked for me: 这种模式对我有用:
-fx-background-image: url('file:C:/Data/example.jpg');
So, in your case it would be: 因此,在您的情况下,它将是:
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;");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.