标题说明了一切。我想更改不可编辑的提示文本的颜色combobox
,使该文本具有与可编辑的提示文本相同的颜色combobox
。在我的 CSS 文件中,我尝试使用-fx-prompt-text-fill
in .combo-box
、和,但没有任何效果。.combo-box-base
.combo-box-base .text-field
.combo-box-base .text-input
我必须使用什么样式类?
标题说明了一切。我想更改不可编辑的提示文本的颜色combobox
,使该文本具有与可编辑的提示文本相同的颜色combobox
。在我的 CSS 文件中,我尝试使用-fx-prompt-text-fill
in .combo-box
、和,但没有任何效果。.combo-box-base
.combo-box-base .text-field
.combo-box-base .text-input
我必须使用什么样式类?
当ComboBox
不可编辑时,没有TextField
,并且该属性-fx-prompt-text-fill
不再有效,因为改为显示的控件 aListCell
不会扩展TextInputControl
。
为了设置这个单元格的样式,我们可以提供我们的自定义样式ListCell
:
@Override
public void start(Stage primaryStage) {
ComboBox comboBox = new ComboBox();
comboBox.getItems().addAll("Item 1", "Item 2", "Item 3");
comboBox.setPromptText("Click to select");
comboBox.setEditable(false);
comboBox.setButtonCell(new ListCell(){
@Override
protected void updateItem(Object item, boolean empty) {
super.updateItem(item, empty);
if(empty || item==null){
// styled like -fx-prompt-text-fill:
setStyle("-fx-text-fill: derive(-fx-control-inner-background,-30%)");
} else {
setStyle("-fx-text-fill: -fx-text-inner-color");
setText(item.toString());
}
}
});
Scene scene = new Scene(new StackPane(comboBox), 300, 250);
primaryStage.setScene(scene);
primaryStage.show();
}
嗨,我相信我正在提供更好的解决方案
第一的
在您的 CSS 文件中创建以下内容
.input .text-field {
-fx-prompt-text-fill: #a0a0a0; // or any color you want
}
在附加 CSS 文件后,在场景构建器中将您的组合框类设置为输入
这对我来说就像一个沙姆