path « JTree « Java Swing Q&A





1. Selection Path of a JTree    stackoverflow.com

I've loaded a JTree with nodes from an XML Schema file using the XSOM API (https://xsom.dev.java.net). Every time a file is selected I do the folowing:

schemaParser = new XSDParser(selectedFile.getAbsolutePath());

TreeModel model = schemaParser.generateTreeModel();
schemaTree.setModel(model);
schemaTree.setCellRenderer(new ...

2. TreePath from path?    coderanch.com

import java.awt.*; import javax.swing.*; import javax.swing.tree.*; public class PathTest { public PathTest() { String filePath = "c:/jexp/tutorial/images/dukeWaveRed.gif"; DefaultMutableTreeNode node = buildNodeFromString(filePath); DefaultMutableTreeNode lastLeaf = node.getLastLeaf(); TreePath path = new TreePath(lastLeaf.getPath()); System.out.println("path = " + path); DefaultTreeModel model = new DefaultTreeModel(node); JTree tree = new JTree(model); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.add(tree); f.setSize(300,300); f.setLocation(200,200); f.setVisible(true); } private DefaultMutableTreeNode buildNodeFromString(String path) { ...

3. JTree last selected path component is giving null    coderanch.com

This seems to work okay. Maybe you can modify it to demonstrate the null values. import java.awt.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.tree.*; public class TreeTest implements TreeSelectionListener { JTree tree; public void valueChanged(TreeSelectionEvent e) { TreePath path = e.getNewLeadSelectionPath(); Object lspc = tree.getLastSelectedPathComponent(); System.out.println("path = " + path + "\n" + "lspc = " + lspc); } private void expandTree() ...

4. Identify the path of the node and insert in JTree.    coderanch.com

I am having two trees and I want to get the node from one tree and insert it into another tree. While inserting if the source node has more parents how to identify the path of the node and insert into the appropriate node in the destination tree. Kindly help me in this issue.

5. Get JTree node by it's tree path    coderanch.com

6. how to get the path of the selected Jtree node for deletion purpose    forums.oracle.com

I had one Jtree which show the file structure of the system now i want to get the functionality like when i right click on the node , it should be delete and the file also deleted from my system, for that how can i get the path of that component i had used TreePath path = tree.getPathForLocation(loc.x, loc.y); but it ...