File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Double Click on Cell in JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Double Click on Cell in JTable" Watch "Double Click on Cell in JTable" New topic

Double Click on Cell in JTable

Suhas Mohamedali

Joined: Jun 05, 2012
Posts: 29

Please help me to handle the double click event in cell of JTable.
I added a mouse listener to the table.
The logic is written on mouseclicked method.
But it recognizes only one click. In the second click the cell becomes editable.

My requirement is to enter a code in the cell. If the user knows the code he can enter in the cell or he need to double click on the cell to open a search panel to search and fins the code.

Please help

Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
initial thoughts are it would make more
sense to use the right-click to open a
search pop-up.

is there a specific reason to use a double-click
Suhas Mohamedali

Joined: Jun 05, 2012
Posts: 29
Dear Michael,

Thanks for your reply.

Yeah we need to open the pop up using double click only as the existing application is so.
In the existing application the following code is used.

Could you please suggest???

column.setCellEditor(new MyEditor(new JTextField()))

Martin Vajsar

Joined: Aug 22, 2010
Posts: 3733

You could use javax.swing.DefaultCellEditor#setClickCountToStart() to set the click count to a large number; double-click won't initiate cell editing then.
Rob Spoor

Joined: Oct 27, 2005
Posts: 20276

Unless someone has a lot of patience
Integer.MAX_VALUE should be a safe enough value though.

How To Ask Questions How To Answer Questions
I agree. Here's the link:
subject: Double Click on Cell in JTable
It's not a secret anymore!