Java Reference
In-Depth Information
Figure 17-12. An editable JTree with the default editor
A series of classes is available to support editing tree nodes. Many are shared with the
JTable component because both can support editable cells. The CellEditor interface forms the
basis for the TreeCellEditor interface. Any editor implementation for a JTree must implement
the TreeCellEditor interface. The DefaultCellEditor (which extends AbstractCellEditor )
offers one such editor implementation, and the DefaultTreeCellEditor offers another. Let's
now look at these interfaces and classes in more detail.
CellEditor Interface
The CellEditor interface defines the necessary basics for any editor used with a JTree or JTable ,
as well as for any third-party components that need an editor. Besides defining how to manage
a list of CellEditorListener objects, the interface describes how to determine if a particular
node or cell is editable and what the new value is after the editor has changed its value.
public interface CellEditor {
// Properties
public Object getCellEditorValue();
// Listeners
public void addCellEditorListener(CellEditorListener l);
public void removeCellEditorListener(CellEditorListener l);
// Other methods
public void cancelCellEditing();
public boolean isCellEditable(EventObject event);
public boolean shouldSelectCell(EventObject event);
public boolean stopCellEditing();
}
TreeCellEditor Interface
The TreeCellEditor interface works similarly to the TreeCellRenderer interface. However, the
get XXX Component() method does not have an argument that tells the editor it has the input
focus, because in the case of an editor, it must already have the input focus. Any class imple-
menting the TreeCellEditor interface can serve as an editor for your JTree .
public interface TreeCellEditor implements CellEditor {
public Component getTreeCellEditorComponent(JTree tree, Object value,
boolean isSelected, boolean expanded, boolean leaf, int row);
}
 
Search WWH ::




Custom Search