how to style a prompt text of combobox in java FX application?

12,466

Solution 1

If you only want to change size of the prompt text, and not the other text, I don't think there is any way: there's simply no hook into the text node for the prompt text that distinguishes it from the displayed text.

You can change the color via a special css property:

.combo-box .text-field {
    -fx-prompt-text-fill: rgba(255, 0, 0, 0.5) ;
}
.combo-box .text-field:focused {
    -fx-prompt-text-fill: transparent ;
}

but I don't see any way to change any other style properties.

Solution 2

just add the following codes at your css

.combo-box-base .text{ -fx-fill: rgb(130.0, 130.0, 130.0); }

Solution 3

Have you checked this out? Try something like:

.combo-box .list-view {
    -fx-font-size: xxxx;
}

You may need to specify additional properties/and or additional selectors to achieve the desired effect (e.g. -fx-cell-size). See the relevant section in caspian.css (located inside the jfxrt.jar in the lib folder of your JRE).

Share:
12,466
Mehdi Boukhechba
Author by

Mehdi Boukhechba

This user needs lots to learn.

Updated on June 30, 2022

Comments

  • Mehdi Boukhechba
    Mehdi Boukhechba almost 2 years

    I want to modify the css style of my combobox to reduce the text-size of its promptText.

    How can this be done?

  • Vishwas Mehra
    Vishwas Mehra about 10 years
    Are you sure this property works with combo boxes? I can't seem to make it work (JDK 7, Scene Builder 1.1). I have a form with multiple TextFields and 2 ComboBoxes. Even if I add a single css file with ".text-field { -fx-prompt-text-fill: rgba(255, 0, 0, 0.5) ; }", all the text field hints turn red but the combo box hints stay as black.
  • James_D
    James_D about 10 years
    Yup, tested on both JDK 7 and JDK 8. You might need to explicitly include .combo-box .text-field {...} in your css file.
  • Vishwas Mehra
    Vishwas Mehra about 10 years
    Ok thanks - yes I tried that and many other combinations. Doesn't work for me - odd.
  • Toby Speight
    Toby Speight about 7 years
    Whilst this code snippet is welcome, and may provide some help, it would be greatly improved if it included an explanation of how and why this solves the problem. Remember that you are answering the question for readers in the future, not just the person asking now! Please edit your answer to add explanation, and give an indication of what limitations and assumptions apply.
  • Sumeet Vishwas
    Sumeet Vishwas over 3 years
    @JJ. does work for me either with all combination. please let me know if you got something