JavaFX 组合框样式按钮(如果可编辑)

标签 java css combobox javafx-2 javafx-8

我在 javafx 中设置组合框按钮的样式时遇到了一个奇怪的情况。目前,我有

.combo-box .arrow {
    -fx-background-color: black;
}

.combo-box .arrow-button {
    -fx-background-color: white;
    -fx-size: 5;
}

设置按钮的背景色为白色,箭头为黑色。如果组合框不可编辑,这很好。但是,如果组合框可编辑,则不会应用此 CSS。

如果组合框是可编辑的,有谁知道如何设置下拉按钮的样式?

public class SSCCE extends Application{

@Override
public void start(Stage primaryStage) throws Exception {
    VBox root = new VBox();
    primaryStage.setScene(new Scene(root));

    ComboBox editable = new ComboBox();
    editable.setEditable(true);
    editable.setPrefWidth(125);

    ComboBox notEditable = new ComboBox();
    notEditable.setEditable(false);
    notEditable.setPrefWidth(125);

    root.getChildren().addAll(editable, notEditable);
    primaryStage.sizeToScene();
    primaryStage.show();

    StyleManager.getInstance().addUserAgentStylesheet("/theme/styles/ComboBox.css");
}

public static void main(String[] args) {
    launch(args);
}

最佳答案

希望现在回答您的问题还不算太晚...为了更改箭头颜色,我们需要通过 CSS combo-box-base 类及其子结构访问它,直到我们到达箭头为止:

.combo-box-base > .arrow-button > .arrow {
    -fx-background-color: white;
}

您可以在 CSS reference for Java 8 中找到它

关于JavaFX 组合框样式按钮(如果可编辑),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25572470/

相关文章:

html - 修复了我的 wrapper 旁边的横幅?

javascript - 根据值输出更改背景颜色

javascript - jQuery Combobox//向下箭头问题

c++ - 防止将 AddString(某些进程)添加到组合框 MFC

java - 我刚刚加载了 22 个可绘制对象,为什么会出现 OutOfMemoryError?

java - 如何将 .jar 上传到 AWS EC2 并重新启动运行它的 JVM?

html - 纯 CSS 图片/缩略图库

c# - WPF ComboBox 忽略 ItemsSource 对象上的 ToString 覆盖

java - 我如何使用 Java 和 Xerces 解析符合 1.1 规范的 XML?

java - 如果提前 1、2、3、4 分钟,如何将其四舍五入到最接近的 5 分钟间隔?