0

从附图中我有一个 jTable在此处输入图像描述

右键单击一行会启动一个 jPopup,其中包含一个项目“Thread Stop”。

我想通过单击此菜单项返回行号

如何做到这一点?

谢谢。

4

2 回答 2

6

在显示弹出窗口的 MouseListener 中,只需通过 JTable 方法获取行号和列号:

  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

     }
  });
于 2012-02-19T19:07:28.350 回答
2

您的实现TableCellEditor包括该行作为参数,但您应该仅在TableModel更新时采取行动,如此处所示TablePopupEditor是一个相关的例子。

于 2012-02-19T19:09:19.867 回答