0

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.

mKorbel
  • 109,525
  • 20
  • 134
  • 319
Alberto acepsut
  • 1,972
  • 10
  • 41
  • 87
  • What do you plan to do with the row number? – trashgod Feb 19 '12 at 18:56
  • Can you add some code where you associate jPopup content "Thread Stop" with a specific row number? It seems you are able to associate them right so you should be able to access row number easily. – Juvanis Feb 19 '12 at 19:01

2 Answers2

6

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

     }
  });
Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
  • 1
    +1 for faster @Alberto acepsut look here http://stackoverflow.com/questions/7423533/jtable-with-jpopupmenu – mKorbel Feb 19 '12 at 19:08
2

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.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045