将自定义元素添加到 JPopupMenu
这个问题可以用两种不同的方式来表述:
1.我有一个JPopupMenu
,我想在其中插入一个不是JMenuItem
的组件(自定义 JTree
)...但我不知道该怎么做
,或者
2. 我有一个不同的 Popup (JPopupPanel
),我想要在我的自定义 JTree
下面添加 JMenuItems
,并且这些 JMenuItems
的工作方式就像插入到 JPopupMenu
中一样:它们当鼠标悬停时突出显示,并且选择其中之一时弹出窗口关闭。
有什么提示吗?
注意:在 2. 中,我可以毫无问题地添加 JMenuItems,显示它们显示在弹出窗口中,但它们的行为不像在 JMenu 或 JPopupMenu 中时那样
The problem can be stated in two different ways:
1. I have a JPopupMenu
where I want to insert a component which is not a JMenuItem
(a custom JTree
)... but I dont know how to do it
or
2. I have a different Popup (JPopupPanel
) and I want to add JMenuItems
below my custom JTree
and that those JMenuItems
work as if they were inserted in a JPopupMenu
: they are highlighted when mouse is over and popup is closed when one of them is selected.
Any hints?
NOTE: in 2. I can add the JMenuItems without problem, show they are shown in the Popup, but they dont act as when they are in a JMenu or JPopupMenu
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于 1.
JPopupMenu
支持使用方法插入任何Component
对于 2. 您是否向菜单添加了 ActionListener?
For 1.
JPopupMenu
supports insertion of anyComponent
with the methodFor 2. Did you add an ActionListener to the menu?