我将如何向弹出菜单添加单选按钮?
我想让 TrayIcon
具有 java.awt.PopupMenu
。我已经知道这部分怎么做了。但 Java 似乎没有 RadioButtonMenuItem
。 我已经尝试向其中添加一个 JRadioButtonMenuItem
,但这导致了许多错误。 有没有一种方法可以合并 3 个“复选框”(不允许一次选择超过 1 个)并将其添加到我的 PopupMenu
中?
I want to have a TrayIcon
have a java.awt.PopupMenu
. I already know how do this part. But it appears that Java doesn't have a RadioButtonMenuItem
.
I already tried to add a JRadioButtonMenuItem
to it, but that resulted in many errors.
Is there a way that I could incorporate 3 "checkboxes" that do not allow more than 1 to be selected at a time and add it to my PopupMenu
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的建议是使用 Swing - 我认为没有理由在这里使用旧的 AWT 菜单。真正的
TrayIcon
是java.awt
的一部分,但周围有代码(请参阅 此处)非常适合我将摆动菜单与 TrayIcon 集成。当然,一旦您进入摇摆区域,您就可以离开,只需使用
JRadioButtonMenuItem
即可。My advice would be to use Swing - there's no reason I can see for using old AWT menus here. True
TrayIcon
is part ofjava.awt
, but there is code around (see here) that works fine for me to integrate a swing menu with a TrayIcon.And of course, once you're in swing territory you're away, just use
JRadioButtonMenuItem
.