且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

找到已调用弹出菜单的JTable行

更新时间:2023-12-04 19:30:34

JTable.rowAtPoint(...);

你可以从MouseEvent获得积分。

You can get the point from the MouseEvent.

编辑:

table.addMouseListener( new MouseAdapter()
{
    public void mouseReleased(MouseEvent e)
    {
        if (e.isPopupTrigger())
        {
            JTable source = (JTable)e.getSource();
            int row = source.rowAtPoint( e.getPoint() );
            int column = source.columnAtPoint( e.getPoint() );

            if (! source.isRowSelected(row))
                source.changeSelection(row, column, false, false);

            popup.show(e.getComponent(), e.getX(), e.getY());
        }
    }
});