更改JRadioButtonMenuItem的选定点颜色 [英] Change selected dot color of JRadioButtonMenuItem
问题描述
我正在使用我的个人Java聊天客户端,其中一个功能是设置用户状态(可用,不可见,忙)。为了使用户友好,我将这些状态放入 JMenu
,其中 JRadioButtonMenuItem
。
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
.
问题是我希望每个状态 RadioButton
都有自己的无线电点颜色(或点图标)。例如:
The problem is I want each status RadioButton
to have its own radio-dot color (or dot-icon). For example:
- [绿点]可用
- [Red-Dot]忙碌
- [Gray-Dot] Invisible。
我想扩展 JRadioButtonMenuItem
有三个不同的自定义 RadioButtonMenuItem
,但无法理解如何绘制 JRadioButtonMenuItem
。
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?
编辑1
感谢您的建议,使用图标
以及 setIcon()
和 setSelectedIcon()
方法。
但是由于我的问题是关于更改无线电点,你还可以帮我隐藏<$ c $中的无线电点c> RadioButton ?
编辑2
这是我应用的当前屏幕截图。$
正如你所看到的那样之前的点 RadioButtonMenuItem
在某种程度上是荒谬的废话。这就是为什么我想摆脱点,或将其更改为我的自定义图标:)
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 :)
推荐答案
单选按钮的点是UI代表为每个Look& amp;感觉。您可以提供自己的 BasicRadioButtonUI
,但努力并非无足轻重。作为替代方案,实现图标
界面,如此处所示 ColorIcon
。
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
.
这篇关于更改JRadioButtonMenuItem的选定点颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!