- java.lang.Object
- 
- javax.swing.tree.DefaultTreeCellEditor
 
- 
- All Implemented Interfaces:
- ActionListener,- EventListener,- CellEditor,- TreeSelectionListener,- TreeCellEditor
 
 public class DefaultTreeCellEditor extends Object implements ActionListener, TreeCellEditor, TreeSelectionListener ATreeCellEditor. You need to supply an instance ofDefaultTreeCellRendererso that the icons can be obtained. You can optionally supply aTreeCellEditorthat will be layed out according to the icon in theDefaultTreeCellRenderer. If you do not supply aTreeCellEditor, aTextFieldwill be used. Editing is started on a triple mouse click, or after a click, pause, click and a delay of 1200 milliseconds.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 JavaBeans™ has been added to the java.beanspackage. Please seeXMLEncoder.- See Also:
- JTree
 
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description classDefaultTreeCellEditor.DefaultTextFieldTextFieldused when no editor is supplied.classDefaultTreeCellEditor.EditorContainerContainer responsible for placing theeditingComponent.
 - 
Field SummaryFields Modifier and Type Field Description protected ColorborderSelectionColorTrue if the border selection color should be drawn.protected booleancanEditAs of Java 2 platform v1.4 this field should no longer be used.protected ComponenteditingComponentComponent used in editing, obtained from theeditingContainer.protected ContainereditingContainerEditing container, will contain theeditorComponent.protected IconeditingIconIcon to use when editing.protected FontfontFont to paint with,nullindicates font of renderer is to be used.protected TreePathlastPathLast path that was selected.protected intlastRowRow that was last passed intogetTreeCellEditorComponent.protected intoffsetUsed in editing.protected TreeCellEditorrealEditorEditor handling the editing.protected DefaultTreeCellRendererrendererRenderer, used to get border and offsets from.protected TimertimerUsed before starting the editing session.protected JTreetreeJTreeinstance listening too.
 - 
Constructor SummaryConstructors Constructor Description DefaultTreeCellEditor(JTree tree, DefaultTreeCellRenderer renderer)Constructs aDefaultTreeCellEditorobject for a JTree using the specified renderer and a default editor.DefaultTreeCellEditor(JTree tree, DefaultTreeCellRenderer renderer, TreeCellEditor editor)Constructs aDefaultTreeCellEditorobject for aJTreeusing the specified renderer and the specified editor.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description voidactionPerformed(ActionEvent e)Messaged when the timer fires, this will start the editing session.voidaddCellEditorListener(CellEditorListener l)Adds theCellEditorListener.voidcancelCellEditing()MessagescancelCellEditingto therealEditorand removes it from this instance.protected booleancanEditImmediately(EventObject event)Returns true ifeventisnull, or it is aMouseEventwith a click count > 2 andinHitRegionreturns true.protected ContainercreateContainer()Creates the container to manage placement ofeditingComponent.protected TreeCellEditorcreateTreeCellEditor()This is invoked if aTreeCellEditoris not supplied in the constructor.protected voiddetermineOffset(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row)Determine the offset.ColorgetBorderSelectionColor()Returns the color the border is drawn.CellEditorListener[]getCellEditorListeners()Returns an array of all theCellEditorListeners added to this DefaultTreeCellEditor with addCellEditorListener().ObjectgetCellEditorValue()Returns the value currently being edited.FontgetFont()Gets the font used for editing.ComponentgetTreeCellEditorComponent(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row)Configures the editor.protected booleaninHitRegion(int x, int y)Returns true if the passed in location is a valid mouse location to start editing from.booleanisCellEditable(EventObject event)If therealEditorreturns true to this message,prepareForEditingis messaged and true is returned.protected voidprepareForEditing()Invoked just before editing is to start.voidremoveCellEditorListener(CellEditorListener l)Removes the previously addedCellEditorListener.voidsetBorderSelectionColor(Color newColor)Sets the color to use for the border.voidsetFont(Font font)Sets the font to edit with.protected voidsetTree(JTree newTree)Sets the tree currently editing for.booleanshouldSelectCell(EventObject event)Messages therealEditorfor the return value.protected booleanshouldStartEditingTimer(EventObject event)Returns true ifeventis aMouseEventand the click count is 1.protected voidstartEditingTimer()Starts the editing timer.booleanstopCellEditing()If therealEditorwill allow editing to stop, therealEditoris removed and true is returned, otherwise false is returned.voidvalueChanged(TreeSelectionEvent e)ResetslastPath.
 
- 
- 
- 
Field Detail- 
realEditorprotected TreeCellEditor realEditor Editor handling the editing.
 - 
rendererprotected DefaultTreeCellRenderer renderer Renderer, used to get border and offsets from.
 - 
editingContainerprotected Container editingContainer Editing container, will contain theeditorComponent.
 - 
editingComponentprotected transient Component editingComponent Component used in editing, obtained from theeditingContainer.
 - 
canEditprotected 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 overrideisCellEditable.
 - 
offsetprotected transient int offset Used in editing. Indicates x position to placeeditingComponent.
 - 
treeprotected transient JTree tree JTreeinstance listening too.
 - 
lastPathprotected transient TreePath lastPath Last path that was selected.
 - 
timerprotected transient Timer timer Used before starting the editing session.
 - 
lastRowprotected transient int lastRow Row that was last passed intogetTreeCellEditorComponent.
 - 
borderSelectionColorprotected Color borderSelectionColor True if the border selection color should be drawn.
 - 
editingIconprotected transient Icon editingIcon Icon to use when editing.
 - 
fontprotected Font font Font to paint with,nullindicates font of renderer is to be used.
 
- 
 - 
Constructor Detail- 
DefaultTreeCellEditorpublic DefaultTreeCellEditor(JTree tree, DefaultTreeCellRenderer renderer) Constructs aDefaultTreeCellEditorobject for a JTree using the specified renderer and a default editor. (Use this constructor for normal editing.)- Parameters:
- tree- a- JTreeobject
- renderer- a- DefaultTreeCellRendererobject
 
 - 
DefaultTreeCellEditorpublic DefaultTreeCellEditor(JTree tree, DefaultTreeCellRenderer renderer, TreeCellEditor editor) Constructs aDefaultTreeCellEditorobject for aJTreeusing the specified renderer and the specified editor. (Use this constructor for specialized editing.)- Parameters:
- tree- a- JTreeobject
- renderer- a- DefaultTreeCellRendererobject
- editor- a- TreeCellEditorobject
 
 
- 
 - 
Method Detail- 
setBorderSelectionColorpublic void setBorderSelectionColor(Color newColor) Sets the color to use for the border.- Parameters:
- newColor- the new border color
 
 - 
getBorderSelectionColorpublic Color getBorderSelectionColor() Returns the color the border is drawn.- Returns:
- the border selection color
 
 - 
setFontpublic void setFont(Font font) Sets the font to edit with.nullindicates the renderers font should be used. This will NOT override any font you have set in the editor the receiver was instantiated with. Ifnullfor an editor was passed in a default editor will be created that will pick up this font.- Parameters:
- font- the editing- Font
- See Also:
- getFont()
 
 - 
getFontpublic Font getFont() Gets the font used for editing.- Returns:
- the editing Font
- See Also:
- setFont(java.awt.Font)
 
 - 
getTreeCellEditorComponentpublic Component getTreeCellEditorComponent(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row) Configures the editor. Passed onto therealEditor.- Specified by:
- getTreeCellEditorComponentin interface- TreeCellEditor
- Parameters:
- tree- the JTree that is asking the editor to edit; this parameter can be null
- value- the value of the cell to be edited
- isSelected- true if the cell is to be rendered with selection highlighting
- expanded- true if the node is expanded
- leaf- true if the node is a leaf node
- row- the row index of the node being edited
- Returns:
- the component for editing
 
 - 
getCellEditorValuepublic Object getCellEditorValue() Returns the value currently being edited.- Specified by:
- getCellEditorValuein interface- CellEditor
- Returns:
- the value currently being edited
 
 - 
isCellEditablepublic boolean isCellEditable(EventObject event) If therealEditorreturns true to this message,prepareForEditingis messaged and true is returned.- Specified by:
- isCellEditablein interface- CellEditor
- Parameters:
- event- the event the editor should use to consider whether to begin editing or not
- Returns:
- true if editing can be started
- See Also:
- CellEditor.shouldSelectCell(java.util.EventObject)
 
 - 
shouldSelectCellpublic boolean shouldSelectCell(EventObject event) Messages therealEditorfor the return value.- Specified by:
- shouldSelectCellin interface- CellEditor
- Parameters:
- event- the event the editor should use to start editing
- Returns:
- true if the editor would like the editing cell to be selected; otherwise returns false
- See Also:
- CellEditor.isCellEditable(java.util.EventObject)
 
 - 
stopCellEditingpublic boolean stopCellEditing() If therealEditorwill allow editing to stop, therealEditoris removed and true is returned, otherwise false is returned.- Specified by:
- stopCellEditingin interface- CellEditor
- Returns:
- true if editing was stopped; false otherwise
 
 - 
cancelCellEditingpublic void cancelCellEditing() MessagescancelCellEditingto therealEditorand removes it from this instance.- Specified by:
- cancelCellEditingin interface- CellEditor
 
 - 
addCellEditorListenerpublic void addCellEditorListener(CellEditorListener l) Adds theCellEditorListener.- Specified by:
- addCellEditorListenerin interface- CellEditor
- Parameters:
- l- the listener to be added
 
 - 
removeCellEditorListenerpublic void removeCellEditorListener(CellEditorListener l) Removes the previously addedCellEditorListener.- Specified by:
- removeCellEditorListenerin interface- CellEditor
- Parameters:
- l- the listener to be removed
 
 - 
getCellEditorListenerspublic CellEditorListener[] getCellEditorListeners() Returns an array of all theCellEditorListeners added to this DefaultTreeCellEditor with addCellEditorListener().- Returns:
- all of the CellEditorListeners added or an empty array if no listeners have been added
- Since:
- 1.4
 
 - 
valueChangedpublic void valueChanged(TreeSelectionEvent e) ResetslastPath.- Specified by:
- valueChangedin interface- TreeSelectionListener
- Parameters:
- e- the event that characterizes the change.
 
 - 
actionPerformedpublic void actionPerformed(ActionEvent e) Messaged when the timer fires, this will start the editing session.- Specified by:
- actionPerformedin interface- ActionListener
- Parameters:
- e- the event to be processed
 
 - 
setTreeprotected void setTree(JTree newTree) Sets the tree currently editing for. This is needed to add a selection listener.- Parameters:
- newTree- the new tree to be edited
 
 - 
shouldStartEditingTimerprotected boolean shouldStartEditingTimer(EventObject event) Returns true ifeventis aMouseEventand the click count is 1.- Parameters:
- event- the event being studied
- Returns:
- whether eventshould starts the editing timer
 
 - 
startEditingTimerprotected void startEditingTimer() Starts the editing timer.
 - 
canEditImmediatelyprotected boolean canEditImmediately(EventObject event) Returns true ifeventisnull, or it is aMouseEventwith a click count > 2 andinHitRegionreturns true.- Parameters:
- event- the event being studied
- Returns:
- whether editing can be started for the given event
 
 - 
inHitRegionprotected boolean inHitRegion(int x, int y)Returns true if the passed in location is a valid mouse location to start editing from. This is implemented to return false ifxis <= 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.- Parameters:
- x- the x-coordinate of the point
- y- the y-coordinate of the point
- Returns:
- true if the passed in location is a valid mouse location
 
 - 
determineOffsetprotected void determineOffset(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row) Determine the offset.- Parameters:
- tree- a- JTreeobject
- value- a value
- isSelected- selection status
- expanded- expansion status
- leaf- leaf status
- row- current row
 
 - 
prepareForEditingprotected void prepareForEditing() Invoked just before editing is to start. Will add theeditingComponentto theeditingContainer.
 - 
createContainerprotected Container createContainer() Creates the container to manage placement ofeditingComponent.- Returns:
- new Container object
 
 - 
createTreeCellEditorprotected TreeCellEditor createTreeCellEditor() This is invoked if aTreeCellEditoris not supplied in the constructor. It returns aTextFieldeditor.- Returns:
- a new TextFieldeditor
 
 
- 
 
-