我'm using a custom JavaFX library called JFoenix that overhauls some JavaFX components with Google'的材料设计 . 选择后我选择了项目'm specifically running into is changing the text color of a ComboBox of Strings'问题 . This is my before screen, with the item in question circled.
当我从ComboBox(see screenshot here)中选择一个项目时,文本从灰色变为黑色 . 我希望所选项目中的文本与其他标签的颜色相同 . 在Scene Builder中添加 -fx-text-fill
或 -fx-text-inner-color
不起作用 .
我发现唯一可行的解决方案是在用户选择一个选项后,使ComboBox可编辑并通过其编辑器设置颜色:
@FXML
private void handleComboBoxFormat() {
this.mpaaBox.getEditor().setStyle("-fx-text-fill: #eceff1;" + "-fx-background-color: #445566");
}
我不喜欢这个解决方案,因为我不希望ComboBox可以编辑,而且只是感觉很乱 . 有没有其他方法来编辑文本颜色?谢谢!
2 回答
-fx-text-fill
未在组合框中定义 .但阅读CSS Reference Guide我看到了结构:
.list-cell
定义-fx-text-fill
继承自Labeled .好吧,所以在弄乱@MouseEvent建议的CSS后,我想出了解决方案 .
打开弹出窗口时,
.combo-box .list-view .list-cell
会影响ComboBox列表中的项目 ..combo-box .list-cell
影响所选项目的标签,这是我访问时遇到的问题 .