检测点击JTable:有时无法识别

时间:2012-08-03 08:34:20

标签: java swing jtable mouseevent mouseclick-event

我有这段代码来检测点击JTable

table.addMouseListener(new java.awt.event.MouseAdapter()
{
    @Override
    public void mouseClicked(java.awt.event.MouseEvent e)
    {

        int row= table.rowAtPoint(e.getPoint());
        int col= table.columnAtPoint(e.getPoint());
        System.out.println(table.getSelectedRow());

        if (e.getClickCount() == 2)
        {

            System.out.println ("Doppio Click");

        }

    }

});

这段代码非常有用,问题是如果我单击一行并在鼠标按钮向上移动之前我向上移动鼠标,则未检测到单击,但在我的JTable中选择了该行。谁能知道如何解决这个问题?谢谢!

1 个答案:

答案 0 :(得分:1)

改为使用MouseListener.mouseReleasedMouseListener.mousePressed事件(检测双击方式是否很快但可以完成)。