【问题标题】:different background in borderpane javafx边框javafx中的不同背景
【发布时间】:2017-11-09 17:50:08
【问题描述】:

我在父布局 BorderPane 的左侧使用了一个 VBox。我想使用一个 css 文件来更改和使用包含我的 VBox 的 BorderPane 左侧的图像背景。我的 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;
} 

有了这个 css 文件,.root 和 .button 中的规则确实适用,但不适用于 .vbox。如何管理 BorderPane 中不同部分的背景。

我使用以下代码行导入 css 文件:

 scene.getStylesheets().add(this.getClass().getResource("/styles/contentStyle.css").toExternalForm());

这是正确的方法吗? css 文件在另一个包中。

【问题讨论】:

    标签: css javafx


    【解决方案1】:

    VBox 没有定义 .vbox 类选择器。解决此问题的一种方法是 在您的 VBox 上设置一个名为 .vbox 的样式类,如下所示:
    myVBox.getStyleClass().add("vbox"); 但是,如果您希望它们都具有该背景,则需要对应用程序中的每个 VBox 执行此操作。

    有关更多信息,请参阅有关HBoxs 的问题:JavaFX: Styling application with CSS Selectors

    【讨论】:

      猜你喜欢
      • 2013-07-06
      • 2017-09-19
      • 2011-10-24
      • 2012-09-05
      • 1970-01-01
      • 1970-01-01
      • 2013-08-31
      • 2011-03-23
      • 1970-01-01
      相关资源
      最近更新 更多