Find the JTable row on which a popup menu has been invoked

后端 未结 2 456
时光取名叫无心
时光取名叫无心 2021-01-12 23:50

I have a JTable and a popup menu that is specific to each row. I want to calculate the row on which the user right-clicked his mouse (Windows L&F) to bring up the popup

2条回答
  •  囚心锁ツ
    2021-01-12 23:52

    If you don't mind selecting your row on right button click, then in the MouseListener use JTable.rowAtPoint() and select the row if it's not selected, and then in the popup listener use JTable.getSelectedRows() to process your rows. Or you can save them in a separate data structure that you can access from your popup menu listener.

提交回复
热议问题