JavaFX 8 - How to change the color of the prompt text of a NOT editable combobox via CSS?

Tags: css,combobox,stylesheet,javafx-8,text-styling

Problem :

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?

Solution :

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.

In order to set the style of this cell, we can provide our custom styled ListCell:

public void start(Stage primaryStage) {
    ComboBox comboBox = new ComboBox();
    comboBox.getItems().addAll("Item 1", "Item 2", "Item 3");
    comboBox.setPromptText("Click to select");

    comboBox.setButtonCell(new ListCell(){

        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");


    Scene scene = new Scene(new StackPane(comboBox), 300, 250);

    CSS Howto..

    How to overwrite an !important CSS property in jQuery

    How can i change jquery-div creation to some other method

    How do I convert scss to css

    How to not repeat a CSS background gradient

    How to make this in html and css?

    How Float divs like twitter?

    CSS - how to set a position of UL in LI

    css: how to access a value that is not used by an element?

    How to remove white border from blur background image

    Hiding and showing
    • on click using Javascript

    How to apply different css margin-top to each children in a list

    How to make table borders invisible with CSS

    CSS select + select How to get first select

    How can I move a div with direction in JavaScript?

    How to change a defined value to a unspecified value by css?

    How to set a div within text?

    How to download an Html page and its internal files in android?

    How to create a multi colored circle in html and css

    How to dynamically scale images per height using pure CSS?

    How to make arrows on both sides of a box using css [duplicate]

    How to gray out a HTML element

    How to center text next to a responsive image in Bootstrap3

    How to get a CSS selector using Selenium WebDriver?

    How to create angled double border effect CSS

    how to fix closure compiler error on css({ float: 'left' }) [duplicate]

    How to use Javascript to close css drop down menu on outside click?

    How to vertical align the text inside a div in responsive layout

    CSS: How to display an image in the background of a fixed-width, centered div?

    How do I change the MVC Bootstrap layout to have more than one columns

    How make something like Facebook Notifications?