Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

double click a node in a jtree

843805Apr 27 2006 — edited Apr 27 2006
hi i have a Jtree with usernames has nodes. how do i generate a code that when a user double clicks a username node, the corresponding code will execute along with what node was clicked on.

for example, a user clicks on username "jonney" and than a new chat window will appear to establish a chat session with jonney.

at the moment when a user selects a node, you are able to create a new chat session, but i want to change it so that the user has to double click their username not just selecting it. similar to msn mesenger.

here is the code i have at the moment.
 public void valueChanged(TreeSelectionEvent event)
      {
          DefaultMutableTreeNode node = (DefaultMutableTreeNode)
                       userTree.getLastSelectedPathComponent();
          
          //get username.
          Object nodeInfo = node.getUserObject();
          String info =nodeInfo.toString();
          
          if(node.isLeaf())
          {
                ChatDialog_c chatting = new ChatDialog_c(crnt_user, info);
        
                Thread t = new Thread(chatting);
         
                chatting.setTitle("I-comm");
                chatting.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                chatting.setSize(430, 200);
                chatting.getSize();
                chatting.setLocation(420,200);
                chatting.setVisible(true);
                t.start();
          }
          
      }
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 25 2006
Added on Apr 27 2006
9 comments
291 views