package com.tutego.insel.ui.tree;

import javax.swing.*;
import javax.swing.tree.*;
import javax.swing.event.*;

public class JTreeDemo
{
  public static void main( String[] args )
  {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    
    DefaultMutableTreeNode root = new DefaultMutableTreeNode( "Wurzel" );
    
    for ( int ast = 0; ast < 4; ast++ )
    {
      DefaultMutableTreeNode node = new DefaultMutableTreeNode( "Knoten " + ast );
      root.add( node );
      
      for ( int blatt = 1; blatt < 4; blatt++ )
        node.add( new DefaultMutableTreeNode("Blatt " + (ast*3+blatt )) );
    }

    JTree tree = new JTree( root );
    frame.add( new JScrollPane( tree ) );
    frame.pack();
    frame.setVisible( true );

    tree.getSelectionModel().addTreeSelectionListener(
      new TreeSelectionListener()
      {
        public void valueChanged( TreeSelectionEvent e )
        {
          TreePath path = e.getNewLeadSelectionPath();
          System.out.println( path );
        }
      }
    );
  }
}
