Change selected dot color of JRadioButtonMenuItem

java, menuitem, radio-button, swing

Solution

The radio button's dot is rendered by the UI delegate for each Look & Feel. You can supply your own `BasicRadioButtonUI`, but the effort is not trivial. As an alternative, implement the `Icon` interface, as shown here in `ColorIcon`.

Problem

I'm working on my personal Java chat client whose one feature is setting user's status (Available, Invisible, Busy). To make it user-friendly, I put those statuses into a `JMenu` with `JRadioButtonMenuItem`. The problem is I want each status `RadioButton` to have its own radio-dot color (or dot-icon). For example: - [Green-Dot] Available - [Red-Dot] Busy - [Gray-Dot] Invisible. I thought of extending the `JRadioButtonMenuItem` with three different custom `RadioButtonMenuItem`, but couldn't understand how `JRadioButtonMenuItem` is painted. Could anyone help me to solve this problem? Edit 1 Thanks for your suggestions to use `Icon` together with `setIcon()` and `setSelectedIcon()` methods. However since my question is about changing the radio-dot, could you also help me to hide the radio-dot from a `RadioButton`? Edit 2 Here's the current screenshot of my app. As you can see the dot before that `RadioButtonMenuItem` is somehow ridiculously nonsense. That's why I want to get rid of the dot, or change it to my custom icon :)

Original source

Related problems