Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.
MyIM menubar screenshot
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 :)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
234 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...