Alberto acepsut
Alberto acepsut

Reputation: 2022

Get jTable row number from popup item

I have a jTable as from the attached picture enter image description here

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

Answers (2)

trashgod
trashgod

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

Hovercraft Full Of Eels
Hovercraft Full Of Eels

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

Related Questions