JavaFX 8 |
您所在的位置:网站首页 › javafx窗口传值 › JavaFX 8 |
问题描述
标题说明了一切.我想更改不可编辑的 combobox 的提示文本的颜色,使文本具有与可编辑的 combobox 的提示文本相同的颜色.在我的 CSS 文件中,我尝试在 .combo-box、.combo-box-base 中使用 -fx-prompt-text-fill, .combo-box-base .text-field 和 .combo-box-base .text-input,但没有任何效果. The title says everything. I want to change the color of the prompt text of a not editable combobox, so that the text has the same color like the prompt text of a editable combobox. In my CSS-file I tried to use -fx-prompt-text-fill in .combo-box, .combo-box-base, .combo-box-base .text-field and .combo-box-base .text-input, but nothing worked. 我必须使用什么样式类? What styleclass do I have to use? 推荐答案当ComboBox不可编辑时,没有TextField,属性-fx-prompt-text-fill 不再有效,因为显示的控件是一个 ListCell,不会扩展 TextInputControl. When the ComboBox is not editable, there is no TextField, and the property -fx-prompt-text-fill is no longer valid, since the control displayed instead, a ListCell, doesn't extend TextInputControl. 为了设置这个单元格的样式,我们可以提供自定义样式的ListCell: In order to set the style of this cell, we can provide our custom styled 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(); } |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |