繁体   English   中英

从弹出项获取jTable行号

[英]Get jTable row number from popup item

我有一个jTable,如图所示 在此处输入图片说明

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

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

如何做到这一点?

谢谢。

在显示弹出窗口的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

     }
  });

TableCellEditor实现将行作为参数包括在内,但仅应在TableModel更新时执行操作,如下所示 TablePopupEditor是一个相关示例。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM