简体   繁体   中英

How to create Right Click Menu in jtable

当用户右键点击jtable中的一行时,我想创建一个下拉菜单。有人建议我怎么做吗?

This is done exactly the same way as other JPopupMenu . You add a MouseListener to the JTable and upon a right-click, you show the JPopupMenu .

Check out the Menus tutorial of 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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM