JavaFX choicebox [combobox] Prompt Text Color

139 Views Asked by At

I am working on a project using JavaFX. I have a question about styling the choicebox control UI. I am new to JavaFX, so please be kind.

For the choicebox UI control, I changed the prompt background color, but kept the prompt text color, menu list text color, menu list background color, selected text color, and selected background color as the default. However, since the choicebox prompt background color is dark, I wanted to change the prompt text color to a shade of white, so that the text is readable. However, I cant seem to change the prompt text color to be white, without also changing the menu list text color to be white. Since the background color of the menu list is also white, when the choicebox menu list is displayed, you cant discern the white menu list text from the white menu list background. In other words, I want to change the prompt text color, but not the menu list text color. Is this possible?

I saw that css stylings are defined in the modena.css file. However things Ive tried using this file as a reference didnt work.

I tried doing this in my custom stylesheet.css, and it changes the prompt text, but also it changes the menu list text (which like I said I am trying to avoid).

stylesheet.css

.choice-box {
  -fx-background-color : #5F9EA0; /* Cadet Blue */
  -fx-text-fill : white;
  -fx-font-family : sans-serif;
  -fx-font-size : 12;
  -fx-font-style : normal;
}

.choice-box .label {
  -fx-text-fill: white;
}

Java code

// main screen
Scene scene1 = new Scene(gridRoot, 600, 600);
scene1.getStylesheets().add("stylesheet.css");
primaryStage.setScene(scene1);
primaryStage.show();

Without -fx-text-fill: white;

enter image description here enter image description here

With -fx-text-fill: white;

enter image description here enter image description here

Please advise.

EDIT: I ended up going with a combo-box / combobox / combo box, because it has scroll bars when the list exceeds a set length. I described how I achieve the combo-box styling here: combo-box styling. To config it the way I wanted to, I had to set these options:

myComboBox.setVisibleRowCount(15);
myComboBox.setEditable(false);
0

There are 0 best solutions below