Java Reference
In-Depth Information
The awkwardness of the JCheckBox editor and custom text field editor within the
DefaultTreeCellEditor leaves the JComboBox as the only TreeCellEditor you'll get from
DefaultCellEditor . However, you still might want to place the combo box editor within a
DefaultTreeCellEditor to display the appropriate type icon next to the node.
DefaultCellEditor Properties
The DefaultCellEditor has only three properties, which are listed in Table 17-4. The editor can
be any AWT component, not just a lightweight Swing component. Keep in mind the hazards of
mixing heavyweight and lightweight components, if you do choose to use a heavyweight compo-
nent as the editor. If you want to find out what the current setting is for the editor component,
ask for the setting of the cellEditorValue property.
Table 17-4. DefaultCellEditor Properties
Property Name
Data Type
Access
cellEditorValue
Object
Read-only
clickCountToStart
int
Read-write
component
Component
Read-only
DefaultTreeCellEditor Class
The DefaultTreeCellEditor class is the TreeCellEditor that is automatically used by a
JTree when you make a tree editable but you don't associate an editor with that tree. The
DefaultTreeCellEditor combines the icons from a TreeCellRenderer with a TreeCellEditor
to return a combined editor.
The default component used as the editor is a JTextField . This text editor is special in that
it tries to limit its height to the original cell renderer and prefers the font of the tree so that it
won't appear out of place. The editor uses two public inner classes to accomplish this feat:
DefaultTreeCellEditor.EditorContainer and DefaultTreeCellEditor.DefaultTextField .
There are two constructors for DefaultTreeCellEditor . Normally, you don't need to call
the first constructor because it's automatically created for you by the user interface when it
determines that the node is editable. However, it may be necessary if you want to customize
the default editor in some manner.
public DefaultTreeCellEditor(JTree tree, DefaultTreeCellRenderer renderer)
JTree tree = new JTree(...);
DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer)tree.getCellRenderer();
TreeCellEditor editor = new DefaultTreeCellEditor(tree, renderer);
public DefaultTreeCellEditor(JTree tree, DefaultTreeCellRenderer renderer,
TreeCellEditor editor)
public static void main (String args[]) {
JTree tree = new JTree(...);
DefaultTreeCellRenderer renderer =
(DefaultTreeCellRenderer)tree.getCellRenderer();
Search WWH ::




Custom Search