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 的选定点颜色
基础教程推荐
- doFilter()是在servlet的工作完成之前还是之后执行的? 2022-01-01
- Maven:无效的目标版本:10 2022-01-01
- JPA惰性列表上的流 2022-01-01
- 如何在相机中应用自定义滤镜 [Surfaceview 预览]. 2022-01-01
- 将 Windows 证书导入 Java 2022-01-01
- 在java中使用xpath和selenium解析HTML表格数据 2022-01-01
- 在springboot中如何给mybatis加拦截器 2023-04-29
- Java ECDSAwithSHA256 签名长度不一致 2022-01-01
- 将 double 转换为 Int,向下舍入 2022-01-01
- 控制台应用程序中的 Java 键盘输入解析 2022-01-01
