Java中Swing中右键单击节点添加JPopup菜单
在 GUI 中,我在 JPanel
的左侧显示一个 JTree
。现在,对于每个Node(leaf)
,在鼠标右键单击时,我想显示JPopup
菜单,要求在右侧中显示有关
。Node
的统计信息>JPanel
由于我是摇摆新手,任何人都可以帮助编写代码吗? 提前致谢。
问候, 图沙尔·多迪亚。
In GUI,I am displaying one JTree
at the left hand side of JPanel
. Now for each Node(leaf)
, on Mouse right click I want to display JPopup
menu asking for displaying the statistics about Node
in right JPanel
.
As i am new to swing,Could any one help with code.
Thanks in Advance.
Regards,
Tushar Dodia.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用 JTree 的方法
然后 TreePath
从用户右键单击的点返回所需的节点。
Use JTree's method
Then TreePath
That returns you desired node from point where user right clicked.
似乎引起了一些混乱(让我自己感到困惑;-) - 所以这里有一个代码片段,用于对 componentPopup 进行目标位置相关配置
Seem to have caused a bit of confusion (confusing myself ;-) - so here's a code snippet for doing target location related configuration of the componentPopup
我采用了@kleopatra 解决方案并对其进行了轻微更改。
也许这不是最好的方法,但对我有用。
I took @kleopatra solution and changed it slightly.
Maybe it isn't the best way but works for me.