Combobox Tree Node Editor : Tree Renderer Editor « Swing JFC « Java






Combobox Tree Node Editor

Combobox Tree Node Editor
  
import java.awt.BorderLayout;

import javax.swing.DefaultCellEditor;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.tree.DefaultTreeCellEditor;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.TreeCellEditor;

public class ComboTreeSample {
  public static void main(String args[]) {
    JFrame frame = new JFrame("Editable Tree");
    JTree tree = new JTree();
    tree.setEditable(true);
    DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) tree
        .getCellRenderer();
    String elements[] = { "Root", "chartreuse", "rugby", "sushi" };
    JComboBox comboBox = new JComboBox(elements);
    comboBox.setEditable(true);
    TreeCellEditor comboEditor = new DefaultCellEditor(comboBox);
    TreeCellEditor editor = new DefaultTreeCellEditor(tree, renderer,
        comboEditor);
    tree.setCellEditor(editor);
    JScrollPane scrollPane = new JScrollPane(tree);
    frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
    frame.setSize(300, 150);
    frame.setVisible(true);
  }
}

           
         
    
  








Related examples in the same category

1.Tree Cell RendererTree Cell Renderer
2.CheckBox Node Tree SampleCheckBox Node Tree Sample
3.extends DefaultTreeCellEditor to create Tree Leaf editorextends DefaultTreeCellEditor to create Tree Leaf editor
4.Tree Changed RendererTree Changed Renderer
5.Build a tree and populate it with custom renderers and editorsBuild a tree and populate it with custom renderers and editors
6.Using DefaultTreeCellRenderer
7.Scrollable Table Cell Renderer
8.This program demonstrates cell rendering and listening to tree selection events.This program demonstrates cell rendering and listening to tree selection events.