我在 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/