如何在单击 JCheckBox 时显示 JPopupMenu?
我在程序(标记为“使用 MiniTimer”)中有一个 JCheckBox
,右键单击时,会显示一个 JPopupMenu
,其中包含选项“关闭时显示”、“最小化时显示” ”、“关闭或最小化时显示”和“不使用 MiniTimer”。当左键单击时,如何使此 JPopupMnu
也出现在 JCheckBox
下方?
请注意,我尝试将 JCheckBox
的 actionPerformed 方法设置为 miniTimerPopupMenu.setVisible(true);
,但是 merel 使 JPopupMenu
出现在屏幕左上角,即使这样,它也不会注册任何与之交互的操作。有人有什么经验或建议想分享吗?
I have a JCheckBox
in a program (labeled "Use MiniTimer") that, when right-clicked, shows a JPopupMenu
with options "Show on Close", "Show on Minimize", "Show on Close or Minimize", and "Do not use MiniTimer". How can I make this JPopupMnu
appear below the JCheckBox
when it is left-clicked, too?
Note that I tried setting the actionPerformed method of the JCheckBox
to miniTimerPopupMenu.setVisible(true);
, but that merel makes the JPopupMenu
appear in the top-left corner of the screen, and even then, it will not register any interactions with it. Does anyone have any experience or suggestions they would like to share?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
阅读 Swing 教程中关于调出弹出菜单 一个工作示例。本教程使用 popup.show(...)。不知道是不是这个区别。
如果您需要更多帮助,请发布说明问题的 SSCCE (http://sscce.org)。
Read the section from the Swing tutorial on Bringing Up a Popup Menu for a working example. The tutorial uses popup.show(...). Don't know if that is the difference.
If you need more help post your SSCCE (http://sscce.org) that demonstrates the problem.
我认为您应该使用 setLocation() 方法设置 miniTimerPopupMenu 的位置,我认为以下代码可以解决问题
然后您可以使用顶部弹出菜单的 y 和 x 位置。
希望这有效
I think you should set the location of the miniTimerPopupMenu using the setLocation() method, I think the following code does the trick
Then you can play with y and x location of the top popupmenu.
Hope this works