Avalon
Avalon

Reputation: 49

How to change color of selected RadioButton in JavaFX [CSS]?

I just want to change the color of the fill circle on a RadioButton. Surprisingly I couldn't find this in documentation. Is it possible?

I found this similar thread with a solution that is not working for me: CSS Change radio button color in JFXRadioButton

Here is how I have tried it (also tried other variations to no avail):

.radio-button .radio {
    -fx-selected-color: yellow;
    -fx-unselected-color: blue;
}

Upvotes: 1

Views: 4626

Answers (1)

Samuel Philipp
Samuel Philipp

Reputation: 11032

-jfx-selected-color and -jfx-unselected-color are not defined in JavaFX. They are attributes from JFoenix (docs). Also -fx-selected-color and -fx-unselected-color are not available in JavaFX.

To change the color of the dot in the RadioButton you can use the :selected pseudoclass like this (docs):

.radio-button:selected .radio .dot {
    -fx-background-color: red;
    -fx-background-insets: 0;
}

Additionally to the -fx-background-color you should set -fx-background-insets: 0;, because otherwise the dot is not exactly in the center anymore.

The result will look like this:

button

Upvotes: 4

Related Questions