Jason S
Jason S

Reputation: 189686

swing: is there a way to change the color of a checkbox/radiobutton?

I would like to add some visual emphasis to a particular checkbox or radiobutton, and it seems like the simplest would be to change the color to green or red. Is there a way to do this?

I know it's possible to define the bitmaps for these elements from scratch, but I would like them to look identical to the base look/feel, except for color.

Upvotes: 3

Views: 1404

Answers (3)

trashgod
trashgod

Reputation: 205785

In addition to using UIManager or BorderFactory, you can place the component on a colored panel, as suggested in this example using a different component.

Upvotes: 1

Tormod
Tormod

Reputation: 464

There is always the option of changing the background or setting a border, but I understand that's not what you had in mind?

I don't think it is possible to change the actual box without fiddling with the Look and Feel. I would love to be proven wrong, of course.

Upvotes: 1

Michael Borgwardt
Michael Borgwardt

Reputation: 346317

You could try using setForeground() and see whether the UI respects that setting. However, it definitely depends on the specific UI class and thus the Look-and-Feel.

Upvotes: 1

Related Questions