S.P*_*Pro 1 css combobox stylesheet text-styling javafx-8
标题说明了一切.我想更改不可编辑的提示文本的颜色combobox
,以便文本具有与可编辑的提示文本相同的颜色combobox
.在我的CSS文件我试图用-fx-prompt-text-fill
的.combo-box
,.combo-box-base
,.combo-box-base .text-field
和.combo-box-base .text-input
,但毫无效果.
我必须使用什么样的风格?
当ComboBox
不可编辑时,没有TextField
,并且该属性-fx-prompt-text-fill
不再有效,因为显示的控件a ListCell
不会延伸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();
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
6816 次 |
最近记录: |