Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JTables and double click events?  RSS feed

 
Fred Hamilton
Ranch Hand
Posts: 684
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
greetings.

I have a JTable sitting in a JFrame. The fields in a row of the JTable will become the arguments of a method call.

In my research I have found a couple of ways to make it happen. I can use some kind of list selection listener. Which fires an event when a row is selected. Or I can just make use of a JButton which calls the getSelectedRow() index of the table.

What I haven't found is a way to double click on a row of the JTable, and fire an event that way.

If someone can point me in the right direction, I'd be grateful.

regards.
 
Fred Hamilton
Ranch Hand
Posts: 684
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, as best as I can determine, you have to "define" double click yourself, by measuring the time between single click events.

I can deal with that no problem. It sounds like the concept of "double Click" is not built into the java API ?
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are your cells editable? I ask because I believe that the default behavior for double clicking is to bring up the cell's editor. To use it for other purposes, I believe that first you have to turn cell editing off. Then you'll likely need to add a mouse listener to the JTable and check that clickCount == 2 (via getClickCount()).
 
Fred Hamilton
Ranch Hand
Posts: 684
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
pete stein wrote:Are your cells editable? I ask because I believe that the default behavior for double clicking is to bring up the cell's editor. To use it for other purposes, I believe that first you have to turn cell editing off. Then you'll likely need to add a mouse listener to the JTable and check that clickCount == 2 (via getClickCount()).


indeed they are editable. I just assumed that could be "turned off".

I looked at getClickCount(). I also see that the click count can be set in a call to a MouseEvent constructor. But all the API doc had to say about that was "Sets the number of clicks associated with an event", which of course is useless information by itself. Nothing in the MouseEvent API deals with "how fast is a double click" that I can see. Unless that is something that is hard coded somewhere. I'll keep looking.

regards.
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fred Hamilton wrote:indeed they are editable. I just assumed that could be "turned off".
You have to turn this off yourself if you want a double click to do something else.
I looked at getClickCount(). I also see that the click count can be set in a call to a MouseEvent constructor. But all the API doc had to say about that was "Sets the number of clicks associated with an event", which of course is useless information by itself. Nothing in the MouseEvent API deals with "how fast is a double click" that I can see. Unless that is something that is hard coded somewhere. I'll keep looking.regards.
I believe that the double-click speed is OS/individual computer dependent. I know that I can change this setting in Windows Vista via the control panel. I've not heard that it can be set by Java, but I'm no prop on this.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!