• Post Reply Bookmark Topic Watch Topic
  • New Topic

JTree double click event

 
Oliver Ng
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I have a simple JTree and i wish for a new window to popup when I double click on a node in the tree. Could someone please aid me in learning how this could be done? All help is greatly appreciated.
The result would look much like say, a contact list for ICQ, where the nodes are the groups, and the leafs are the contacts. Like ICQ, i want a box to popup on doubleclick (and only a double click) for the selected Jtree leaf.
I registered a mouseListener and tree selection listener but there doesn't seem to be any type of listener for double clicks on tree elements.
Thanks
Oliver
 
Raja Kannappan
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your mouse listener, in
mousePressed(MouseEvent e) method
do this: if (e.getSource() instanceof MyTree)
Inside this if, check for
if (e.getClickCount() == 2)
This way you can check for double-clicks in your tree.
- Raja.
 
Oliver Ng
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my apologies i'm so dumb... there is an example right in the JTree API...
thank you for the help though..
Oliver
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!