javafx - 样式弹出窗口

时间:2013-07-09 15:08:14

标签: combobox javafx-2

我有一个ComboBox,我可以通过CSS设置它。但是,combo-box-popup的{​​{1}}组件无法从同一个css文件设置样式。

我的理论是,ComboBox的弹出窗口不是当前场景的一部分(因为它是一个新窗口),并且因为css文件被添加到包含的样式表的列表中ComboBox,我需要以某种方式将此css文件添加到弹出窗口的样式表列表中。

几个月前,我在设计AnchorPane时遇到了同样的问题。

如何设置Tooltip组件的样式?

1 个答案:

答案 0 :(得分:2)

> 如何设置combo-box-popup组件的样式?

这取决于您要设置样式的弹出窗口的属性。由于它也有own subnodes,因此您需要设置样式:

 - combo-box-popup : a PopupControl that is displayed when the button is pressed  
     - list-view : a ListView  
         - list-cell : a ListCell

caspian.css使用以下默认值:

.combo-box-popup .list-view {
    -fx-background-color: -fx-box-border, -fx-control-inner-background;
    -fx-background-insets: 0, 1;
    -fx-effect: dropshadow( three-pass-box , rgba(0,0,0,0.6) , 8, 0.0 , 0 , 0 );
}

.combo-box-popup .list-view .list-cell {
    -fx-padding: 4 0 4 5;

    /* No alternate highlighting */
    -fx-background-color: -fx-control-inner-background;
}

.combo-box-popup .list-view .list-cell:filled:selected, .combo-box-popup .list-view .list-cell:filled:selected:hover {
    -fx-background: -fx-accent;
    -fx-background-color: -fx-selection-bar;
    -fx-text-fill: -fx-selection-bar-text;
}

.combo-box-popup .list-view .list-cell:filled:hover {
    -fx-background-color: -fx-cell-hover-color;
    -fx-text-fill: -fx-text-inner-color;
}

> 我的理论是,ComboBox的弹出窗口不是当前场景的一部分(因为它是一个新窗口),并且因为css文件被添加到包含AnchorPane

的样式表列表

不,这是场景的一部分。如果没有所有者,则无法显示PopupControl,但是当将css样式表添加到布局而不是场景时,您的.combo-box-popup未应用是正确的。我认为这是一个错误,你可以提交它。现在的解决方法是直接添加到场景中:

scene.getStylesheets().add(getClass().getResource("style.css").toExternalForm());
相关问题