public class javax.swing.tree
DefaultTreeCellEditor


Show All Login
Java SE 6
  
Implements: ActionListener, TreeCellEditor, TreeSelectionListener
Inner classes: DefaultTreeCellEditor.DefaultTextField, DefaultTreeCellEditor.EditorContainer
Details
A TreeCellEditor. You need to supply an instance of DefaultTreeCellRenderer so that the icons can be obtained. You can optionally supply a TreeCellEditor that will be layed out according to the icon in the DefaultTreeCellRenderer. If you do not supply a TreeCellEditor, a TextField will be used. Editing is started on a triple mouse click, or after a click, pause, click and a delay of 1200 miliseconds.

Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeansTM has been added to the java.beans package. Please see java.beans.XMLEncoder.
version1.32 04/07/06
See also javax.swing.JTree


Fields
protected TreeCellEditor realEditor
Editor handling the editing.
protected DefaultTreeCellRenderer renderer
Renderer, used to get border and offsets from.
protected Container editingContainer
Editing container, will contain the editorComponent.
protected Component editingComponent
Component used in editing, obtained from the editingContainer.
protected boolean canEdit
As of Java 2 platform v1.4 this field should no longer be used. If you wish to provide similar behavior you should directly override isCellEditable.
protected int offset
Used in editing. Indicates x position to place editingComponent.
protected JTree tree
JTree instance listening too.
protected TreePath lastPath
Last path that was selected.
protected Timer timer
Used before starting the editing session.
protected int lastRow
Row that was last passed into getTreeCellEditorComponent.
protected Color borderSelectionColor
True if the border selection color should be drawn.
protected Icon editingIcon
Icon to use when editing.
protected Font font
Font to paint with, null indicates font of renderer is to be used.

Constructors
public DefaultTreeCellEditor(JTree tree, DefaultTreeCellRenderer renderer) Details
Constructs a DefaultTreeCellEditor object for a JTree using the specified renderer and a default editor. (Use this constructor for normal editing.)
treea JTree object
renderera DefaultTreeCellRenderer object
public DefaultTreeCellEditor(JTree tree, DefaultTreeCellRenderer renderer, TreeCellEditor editor) Details
Constructs a DefaultTreeCellEditor object for a JTree using the specified renderer and the specified editor. (Use this constructor for specialized editing.)
treea JTree object
renderera DefaultTreeCellRenderer object
editora TreeCellEditor object

Methods
public void actionPerformed(ActionEvent e)
Messaged when the timer fires, this will start the editing session.
public void addCellEditorListener(CellEditorListener l) Details
Adds the CellEditorListener.
lthe listener to be added
public void cancelCellEditing()
Messages cancelCellEditing to the realEditor and removes it from this instance.
protected boolean canEditImmediately(EventObject event) Details
Returns true if event is null, or it is a MouseEvent with a click count > 2 and inHitRegion returns true.
eventthe event being studied
protected Container createContainer()
Creates the container to manage placement of editingComponent.
protected TreeCellEditor createTreeCellEditor() Details
This is invoked if a TreeCellEditor is not supplied in the constructor. It returns a TextField editor.
returna new TextField editor
protected void determineOffset(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row)
protected boolean inHitRegion(int x, int y) Details
Returns true if the passed in location is a valid mouse location to start editing from. This is implemented to return false if x is <= the width of the icon and icon gap displayed by the renderer. In other words this returns true if the user clicks over the text part displayed by the renderer, and false otherwise.
xthe x-coordinate of the point
ythe y-coordinate of the point
returntrue if the passed in location is a valid mouse location
protected void prepareForEditing()
Invoked just before editing is to start. Will add the editingComponent to the editingContainer.
public void removeCellEditorListener(CellEditorListener l) Details
Removes the previously added CellEditorListener.
lthe listener to be removed
public boolean shouldSelectCell(EventObject event)
Messages the realEditor for the return value.
protected boolean shouldStartEditingTimer(EventObject event) Details
Returns true if event is a MouseEvent and the click count is 1.
eventthe event being studied
protected void startEditingTimer()
Starts the editing timer.
public boolean stopCellEditing()
If the realEditor will allow editing to stop, the realEditor is removed and true is returned, otherwise false is returned.
public void valueChanged(TreeSelectionEvent e)
Resets lastPath.

Properties
public void setBorderSelectionColor(Color newColor) Details
Sets the color to use for the border.
newColorthe new border color
public Color getBorderSelectionColor() Details
Returns the color the border is drawn.
returnthe border selection color
public boolean isCellEditable(EventObject event)
If the realEditor returns true to this message, prepareForEditing is messaged and true is returned.
public CellEditorListener[] getCellEditorListeners() Details
Returns an array of all the CellEditorListeners added to this DefaultTreeCellEditor with addCellEditorListener().
returnall of the CellEditorListeners added or an empty array if no listeners have been added
since1.4
public Object getCellEditorValue() Details
Returns the value currently being edited.
returnthe value currently being edited
public void setFont(Font font) Details
Sets the font to edit with. null indicates the renderers font should be used. This will NOT override any font you have set in the editor the receiver was instantied with. If null for an editor was passed in a default editor will be created that will pick up this font.
fontthe editing Font
See also getFont
public Font getFont() Details
Gets the font used for editing.
returnthe editing Font
See also setFont
protected void setTree(JTree newTree) Details
Sets the tree currently editing for. This is needed to add a selection listener.
newTreethe new tree to be edited
public Component getTreeCellEditorComponent(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row)
Configures the editor. Passed onto the realEditor.