JTree With Nodes From An XML File

Sample coding:

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import javax.swing.event.*;

import javax.swing.tree.*;

import java.util.*;

public class Test3 extends JFrame {

JTree jt1 = new JTree(), jt2 = new JTree(new DefaultMutableTreeNode());

public Test3() {


Container content = getContentPane();

Vector v = new Vector();

Enumeration e = ((DefaultMutableTreeNode)((DefaultTreeModel)jt1.getModel()).getRoot()).breadthFirstEnumeration();

while (e.hasMoreElements()) v.add(e.nextElement());

final JList jl = new JList(v);

content.add(new JScrollPane(jl), BorderLayout.WEST);

jl.addListSelectionListener(new ListSelectionListener() {

public void valueChanged(ListSelectionEvent lse) {




JSplitPane jsp = new JSplitPane(JSplitPane.VERTICAL_SPLIT,new JScrollPane(jt1),

new JScrollPane(jt2));



jt1.addTreeSelectionListener(new TreeSelectionListener() {

public void valueChanged(TreeSelectionEvent tse) {







public static void main(String[] arghs) { new Test3(); }


Do you have a Java Problem?
Ask It in The Java Forum

Java Books
Java Certification, Programming, JavaBean and Object Oriented Reference Books

Return to : Java Programming Hints and Tips

All the site contents are Copyright © www.erpgreat.com and the content authors. All rights reserved.
All product names are trademarks of their respective companies.
The site www.erpgreat.com is not affiliated with or endorsed by any company listed at this site.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
 The content on this site may not be reproduced or redistributed without the express written permission of
www.erpgreat.com or the content authors.