Java Reference
In-Depth Information
DefaultTreeCellEditor
class. The
DefaultCellEditor
is primarily for use within a
JTable
, not
a
JTree
.
Figure 17-13.
An editable JTree with a JComboBox editor
■
Caution
When you use a noneditable
JComboBox
as the cell editor, if the set of choices doesn't include
the original node setting, it's impossible to get back to the original setting once the node value changes.
To see how awkward the appearance of a
JCheckBox
is with the
DefaultCellEditor
as a
TreeCellEditor
, take a look at Figure 17-14.
Figure 17-14.
An editable JTree with a JCheckBox editor
Figure 17-14 uses the following source:
Object array[] =
{Boolean.TRUE, Boolean.FALSE, "Hello"}; // Hello will map to false
JTree tree = new JTree(array);
tree.setEditable(true);
tree.setRootVisible(true);
JCheckBox checkBox = new JCheckBox();
TreeCellEditor editor = new DefaultCellEditor(checkBox);
tree.setCellEditor(editor);
■
Note
Use of the
JCheckBox
with the
DefaultCellEditor
isn't recommended with a
JTree
. See the
“Creating a Better Check Box Node Editor” section later in this chapter for an implementation that's more
appropriate for a tree.