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 的选定点颜色
基础教程推荐
- 如何对 Java Hashmap 中的值求和 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
