Change selected dot color of JRadioButtonMenuItem(更改 JRadioButtonMenuItem 的选定点颜色)
问题描述
我正在开发我的个人 Java 聊天客户端,它的一个功能是设置用户状态(可用、不可见、忙碌).为了使其用户友好,我将这些状态放入带有 JRadioButtonMenuItem
的 JMenu
中.
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:
- [绿点] 可用
- [红点] 忙碌
- [灰点] 不可见.
我想用三个不同的自定义 RadioButtonMenuItem
扩展 JRadioButtonMenuItem
,但不明白 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
感谢您建议将 Icon
与 setIcon()
和 setSelectedIcon()
方法一起使用.
但是,由于我的问题是关于更改单选点,您能否帮我隐藏 RadioButton
中的单选点?
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
?
编辑 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 &感觉.您可以提供自己的 BasicRadioButtonUI
,但付出的努力并非微不足道.作为替代方案,实现 Icon
接口,如 here in 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 的选定点颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:更改 JRadioButtonMenuItem 的选定点颜色
基础教程推荐
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- 降序排序:Java Map 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01