Tree.leafIcon : JTree « javax.swing « Java by API






Tree.leafIcon

  
import java.awt.BorderLayout;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JTree;
import javax.swing.UIManager;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;

public class MainClass extends JFrame {
  JTree tree;

  DefaultTreeModel treeModel;

  public MainClass() {
    super("Tree Test Example");
    setSize(200, 150);
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    UIManager.put("Tree.leafIcon", new ImageIcon("leafIcon.gif"));
    UIManager.put("Tree.openIcon", new ImageIcon("openIcon.gif"));
    UIManager.put("Tree.closedIcon", new ImageIcon("closedIcon.gif"));
    UIManager.put("Tree.expandedIcon", new ImageIcon("expandedIcon.gif"));
    UIManager.put("Tree.collapsedIcon", new ImageIcon("collapsedIcon"));
  }

  public void init() {
    DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root");
    DefaultMutableTreeNode subroot = new DefaultMutableTreeNode("SubRoot");
    DefaultMutableTreeNode leaf1 = new DefaultMutableTreeNode("Leaf 1");
    DefaultMutableTreeNode leaf2 = new DefaultMutableTreeNode("Leaf 2");

    treeModel = new DefaultTreeModel(root);
    tree = new JTree(treeModel);

    treeModel.insertNodeInto(subroot, root, 0);
    subroot.add(leaf1);
    root.add(leaf2);

    tree.putClientProperty("JTree.lineStyle", "Angled");
    getContentPane().add(tree, BorderLayout.CENTER);
  }

  public static void main(String args[]) {
    MainClass tt = new MainClass();
    tt.init();
    tt.setVisible(true);
  }
}

           
         
    
  








Related examples in the same category

1.Tree.closedIcon
2.Tree.collapsedIcon
3.Tree.expandedIcon
4.Tree.openIcon
5.JTree.DynamicUtilTreeNode: createChildren(DefaultMutableTreeNode parent, Object children)
6.new JTree()
7.new JTree(TreeNode root)
8.new JTree(Vector vector)
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)