Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Style ChoiceBox in JavaFX

Tags:

java

css

javafx

How can you style a ChoiceBox in JavaFX with CSS? The only things I have found out is how to change the background and the text color.

// Background Color
.cb {
   -fx-background-color: #HEX;
}

// Text Color
.cb .label {
   -fx-text-fill
}

enter image description here

What I am still missing is the highlighting color when hovering the items and the background color of the dropdown list. Also the little arrow. Unfortunately I have found no documentation or anything that helps.

EDIT:

@James_D gave a great link to find out stylings: Modena.css

That way I figured out how to color the white background black.

.cb .context-menu {
   -fx-background-color: black;
}
like image 489
TomTom Avatar asked Nov 22 '25 00:11

TomTom


1 Answers

For the highlighting color:

.cb .menu-item:focused {
  -fx-background-color: yellow ; /* for example */
}

The background color of the dropdown list:

.cb .context-menu {
    -fx-background-color: antiquewhite ;
}

For the arrow:

.cb {
  -fx-mark-color: green ;
}
like image 87
James_D Avatar answered Nov 23 '25 12:11

James_D



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!