Reputation: 2022
I have a jTable as from the attached picture
Right click on a row starts a jPopup, with a single item "Thread Stop".
I would like to return the row number by clicking on this menu item
How to accomplish this?
Thanks.
Upvotes: 0
Views: 834
Reputation: 205795
Your implementation of TableCellEditor
includes the row as a parameter, but you should act only when the TableModel
is updated, as shown here. TablePopupEditor
is a related example.
Upvotes: 2
Reputation: 285405
In your MouseListener where you show your popup, simply get the row and column numbers via the JTable methods:
table.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
Point p = e.getPoint();
int row = table.rowAtPoint(p);
int col = table.columnAtPoint(p);
System.out.printf("row, col: [%d, %d]%n", row, col);
// show pop-up menu here
}
});
Upvotes: 6