[英]different background in borderpane javafx
I am using a VBox in the left position of my parent layout BorderPane. 我在父布局BorderPane的左侧使用了VBox。 I want to use a css file to change and use an image background on the left side of the BorderPane which contains my VBox. 我想使用css文件更改并使用包含我的VBox的BorderPane左侧的图像背景。 I have the following in my ccs file but cant manage it to work. 我的ccs文件中包含以下内容,但无法对其进行管理。
.vbox{
-fx-background-image: url("/ui/image11.jpg");
-fx-background-repeat: no-repeat;
-fx-background-position: center center;
-fx-background-size: 500 500;
}
.root{
-fx-background-color: #ecf0f1;
-fx-background-position: center center;
-fx-background-size: 500 500;
}
.button{
-fx-text-fill: #ecf0f1;
-fx-background-color: #455d7a;
-fx-position: center;
-fx-min-width: 150px;
-fx-transition-duration: 1;
}
With this css file, rules in .root and .button do apply but not on .vbox. 对于此css文件,.root和.button中的规则确实适用,但不适用于.vbox。 How can I manage the backgrounds of the different sections in BorderPane. 如何在BorderPane中管理不同部分的背景。
I import the css file with the following line of code: 我使用以下代码行导入css文件:
scene.getStylesheets().add(this.getClass().getResource("/styles/contentStyle.css").toExternalForm());
Is this the correct way? 这是正确的方法吗? The css file is in another package. css文件在另一个软件包中。
VBox
doesn't have a .vbox
class selector defined. VBox
没有定义.vbox
类选择器。 One way to fix this is to set a styleclass on your VBox called .vbox
, like this: 解决此问题的一种方法是在VBox上设置一个名为.vbox
,如下所示:
myVBox.getStyleClass().add("vbox");
but you would need to do that for each VBox in your application if you wanted them all to have that background. 但如果您希望所有VBox都具有该背景,则需要对应用程序中的每个VBox进行此操作。
See this question about HBox
s: JavaFX: Styling application with CSS Selectors for more info. 有关更多信息,请参见有关HBox
的以下问题: JavaFX:使用CSS选择器样式化应用程序 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.