• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to add child node on right click of a node to a JTree

 
Shweta Baranwal
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,


I have to add a child new node on right click of a parent node to JTree. The JTree should work same as tree works while we explore things in myComputer.
Please tell me if it is possible or not? If yes then please help me to do this...
 
Rob Spoor
Sheriff
Pie
Posts: 20665
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It works if you use a DefaultTreeModel, with TreeNodes.

Upon right clicking (use a MouseListener and its isPopupTrigger method), you create a new TreeNode (usually DefaultMutableTreeNode), retrieve the model from the JTree, and call its insertNodeInto method:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic