Luca
Luca

Reputation: 1874

Detect click on JTable: sometimes not recognized

I've this code to detect click on 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");

        }

    }

});

This code work great the problem is that if I click on a row and before mouse button up I move mouse up the click is not detected but the row is selected in my JTable. Can anyone know how to fix that problem? Thanks!

Upvotes: 1

Views: 1978

Answers (1)

dacwe
dacwe

Reputation: 43504

Use MouseListener.mouseReleased or MouseListener.mousePressed events instead (to detect double clicking that way is tricker but could be done).

Upvotes: 2

Related Questions