aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes How to add child node on right click of a node to a JTree Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to add child node on right click of a node to a JTree" Watch "How to add child node on right click of a node to a JTree" New topic
Author

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

Shweta Baranwal
Greenhorn

Joined: Jun 19, 2008
Posts: 18
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

Joined: Oct 27, 2005
Posts: 19552
    
  16

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:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to add child node on right click of a node to a JTree
 
Similar Threads
JTree problem
JTree / Resizable question
JTree
Vector to Jtree
JTree with CheckBox