[英]How to create Right Click Menu in jtable
当用户右键点击jtable中的一行时,我想创建一个下拉菜单。有人建议我怎么做吗?
This is done exactly the same way as other JPopupMenu
. 这与其他JPopupMenu
完全相同。 You add a MouseListener
to the JTable
and upon a right-click, you show the JPopupMenu
. 将MouseListener
添加到JTable
,右键单击,显示JPopupMenu
。
Check out the Menus tutorial of Oracle 查看Oracle的菜单教程
As mentionned by @kleopatra, you can also directly set a JPopupMenu
on any JComponent
(or its descendendants, using setInheritsPopupMenu()
), with setComponentPopupMenu()
which will take care for you of showing the associated JPopupMenu
, when appropriate (ie, a right-click on most platform) 正如@kleopatra所提到的,您也可以使用setComponentPopupMenu()
直接在任何JComponent
(或其后代,使用setInheritsPopupMenu()
)上设置JPopupMenu
,这将在适当的时候照顾您显示关联的JPopupMenu
(即右侧) - 点击大多数平台)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.