new JTree(Vector vector) : JTree « javax.swing « Java by API






new JTree(Vector vector)

  
import java.awt.BorderLayout;
import java.util.Vector;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreePath;

public class MainClass {
  public static void main(String args[]) {
    JFrame frame = new JFrame("Swing Package Hierarchy");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Vector rootVector = new TreeVector("A", new String[] { "a" });
    JTree tree = new JTree(rootVector);
    tree.setRootVisible(true);
    TreeModel model = tree.getModel();
    model.valueForPathChanged(new TreePath(model.getRoot()), "javax.swing");
    ((DefaultTreeModel) model).reload();

    JScrollPane scrollPane = new JScrollPane(tree);
    frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
    frame.setSize(300, 300);
    frame.setVisible(true);
  }
}

class TreeVector extends Vector {
  String name;

  TreeVector(String name) {
    this.name = name;
  }

  TreeVector(String name, Object elements[]) {
    this.name = name;
    for (int i = 0, n = elements.length; i < n; i++) {
      add(elements[i]);
    }
  }

  public String toString() {
    return name;
  }
}

           
         
    
  








Related examples in the same category

1.Tree.closedIcon
2.Tree.collapsedIcon
3.Tree.expandedIcon
4.Tree.leafIcon
5.Tree.openIcon
6.JTree.DynamicUtilTreeNode: createChildren(DefaultMutableTreeNode parent, Object children)
7.new JTree()
8.new JTree(TreeNode root)
9.JTree: addTreeSelectionListener(TreeSelectionListener tsl)
10.JTree: addTreeWillExpandListener(TreeWillExpandListener tel)
11.JTree: convertValueToText(Object v,boolean s,boolean e,boolean l,int r,boolean h)
12.JTree: getCellRenderer()
13.JTree: getLeadSelectionRow()
14.JTree: getMaxSelectionRow()
15.JTree: getMinSelectionRow()
16.JTree: getNextMatch(String prefix, int startingRow, Bias bias)
17.JTree: getPathForLocation(int x, int y)
18.JTree: getRowHeight()
19.JTree: getSelectionRows()
20.JTree: putClientProperty('JTree.lineStyle', 'None')
21.JTree: setAutoscrolls(boolean b)
22.JTree: setCellEditor(TreeCellEditor editor)
23.JTree: setExpandedState(TreePath path, boolean state)
24.JTree: setRowHeight(int rowHeight)
25.JTree: setTransferHandler(TransferHandler newHandler) (Drag and drop files from file explore)