APIdia Launch Partner
Top Description Inners Fields Constructors Methods
javax.swing.tree

public Class DefaultTreeCellEditor

extends Object
implements ActionListener, TreeCellEditor, TreeSelectionListener
Class Inheritance
All Implemented Interfaces
javax.swing.event.TreeSelectionListener, java.util.EventListener, javax.swing.tree.TreeCellEditor, javax.swing.CellEditor, java.awt.event.ActionListener
Known Direct Subclasses
javax.swing.plaf.synth.SynthTreeUI.SynthTreeCellEditor
Imports
javax.swing.*, javax.swing.border.*, javax.swing.event.*, javax.swing.plaf.FontUIResource, java.awt.*, java.awt.event.*, java.beans.BeanProperty, java.util.EventObject

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 laid 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 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.beans package. Please see java.beans.XMLEncoder.

Author
Scott Violet
See Also
javax.swing.JTree

Nested and Inner Type Summary

Modifier and TypeClass and Description
public class
DefaultTreeCellEditor.DefaultTextField

TextField used when no editor is supplied.

public class
DefaultTreeCellEditor.EditorContainer

Container responsible for placing the editingComponent.

Field Summary

Modifier and TypeField and Description
protected Color
borderSelectionColor

True if the border selection color should be drawn.

protected boolean
canEdit

As of Java 2 platform v1.4 this field should no longer be used.

protected transient Component
editingComponent

Component used in editing, obtained from the editingContainer.

protected Container
editingContainer

Editing container, will contain the editorComponent.

protected transient Icon
editingIcon

Icon to use when editing.

protected Font
font

Font to paint with, null indicates font of renderer is to be used.

protected transient TreePath
lastPath

Last path that was selected.

protected transient int
lastRow

Row that was last passed into getTreeCellEditorComponent.

protected transient int
offset

Used in editing.

protected TreeCellEditor
realEditor

Editor handling the editing.

protected DefaultTreeCellRenderer
renderer

Renderer, used to get border and offsets from.

protected transient Timer
timer

Used before starting the editing session.

protected transient JTree
tree

JTree instance listening too.

Constructor Summary

AccessConstructor and Description
public
DefaultTreeCellEditor(JTree
a JTree object
tree
,
DefaultTreeCellRenderer
a DefaultTreeCellRenderer object
renderer
)

Constructs a DefaultTreeCellEditor object for a JTree using the specified renderer and a default editor.

public
DefaultTreeCellEditor(JTree
a JTree object
tree
,
DefaultTreeCellRenderer
a DefaultTreeCellRenderer object
renderer
,
TreeCellEditor
a TreeCellEditor object
editor
)

Constructs a DefaultTreeCellEditor object for a JTree using the specified renderer and the specified editor.

Method Summary

Modifier and TypeMethod and Description
public void
actionPerformed(ActionEvent e)

Implements java.awt.event.ActionListener.actionPerformed.

Messaged when the timer fires, this will start the editing session.

public void
addCellEditorListener(CellEditorListener
the listener to be added
l
)

Implements javax.swing.CellEditor.addCellEditorListener.

Adds the CellEditorListener.

public void
cancelCellEditing()

Implements javax.swing.CellEditor.cancelCellEditing.

Messages cancelCellEditing to the realEditor and removes it from this instance.

protected boolean

Returns:

whether editing can be started for the given event
canEditImmediately
(EventObject
the event being studied
event
)

Returns true if event is null, or it is a MouseEvent with a click count > 2 and inHitRegion returns true.

private void
cleanupAfterEditing()

Cleans up any state after editing has completed.

protected Container

Returns:

new Container object
createContainer
()

Creates the container to manage placement of editingComponent.

protected TreeCellEditor

Returns:

a new TextField editor
createTreeCellEditor
()

This is invoked if a TreeCellEditor is not supplied in the constructor.

protected void
determineOffset(JTree
a JTree object
tree
,
Object
a value
value
,
boolean
selection status
isSelected
,
boolean
expansion status
expanded
,
boolean
leaf status
leaf
,
int
current row
row
)

Determine the offset.

public Color

Returns:

the border selection color
getBorderSelectionColor
()

Returns the color the border is drawn.

public CellEditorListener[]

Returns:

all of the CellEditorListeners added or an empty array if no listeners have been added
getCellEditorListeners
()

Returns an array of all the CellEditorListeners added to this DefaultTreeCellEditor with addCellEditorListener().

public Object

Returns:

the value currently being edited
getCellEditorValue
()

Implements javax.swing.CellEditor.getCellEditorValue.

Returns the value currently being edited.

public Font

Returns:

the editing Font
getFont
()

Gets the font used for editing.

public Component
getTreeCellEditorComponent(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row)

Implements javax.swing.tree.TreeCellEditor.getTreeCellEditorComponent.

Configures the editor.

protected boolean

Returns:

true if the passed in location is a valid mouse location
inHitRegion
(int
the x-coordinate of the point
x
,
int
the y-coordinate of the point
y
)

Returns true if the passed in location is a valid mouse location to start editing from.

public boolean
isCellEditable(EventObject event)

Implements javax.swing.CellEditor.isCellEditable.

If the realEditor returns true to this message, prepareForEditing is messaged and true is returned.

protected void
prepareForEditing()

Invoked just before editing is to start.

public void
removeCellEditorListener(CellEditorListener
the listener to be removed
l
)

Implements javax.swing.CellEditor.removeCellEditorListener.

Removes the previously added CellEditorListener.

public void
setBorderSelectionColor(Color
the new border color
newColor
)

Sets the color to use for the border.

public void
setFont(Font
the editing Font
font
)

Sets the font to edit with.

protected void
setTree(JTree
the new tree to be edited
newTree
)

Sets the tree currently editing for.

public boolean
shouldSelectCell(EventObject event)

Implements javax.swing.CellEditor.shouldSelectCell.

Messages the realEditor for the return value.

protected boolean

Returns:

whether event should starts the editing timer
shouldStartEditingTimer
(EventObject
the event being studied
event
)

Returns true if event is a MouseEvent and the click count is 1.

protected void
startEditingTimer()

Starts the editing timer.

public boolean
stopCellEditing()

Implements javax.swing.CellEditor.stopCellEditing.

If the realEditor will allow editing to stop, the realEditor is removed and true is returned, otherwise false is returned.

public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

borderSelectionColorback to summary
protected Color borderSelectionColor

True if the border selection color should be drawn.

canEditback to summary
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.

editingComponentback to summary
protected transient Component editingComponent

Component used in editing, obtained from the editingContainer.

editingContainerback to summary
protected Container editingContainer

Editing container, will contain the editorComponent.

editingIconback to summary
protected transient Icon editingIcon

Icon to use when editing.

fontback to summary
protected Font font

Font to paint with, null indicates font of renderer is to be used.

lastPathback to summary
protected transient TreePath lastPath

Last path that was selected.

lastRowback to summary
protected transient int lastRow

Row that was last passed into getTreeCellEditorComponent.

offsetback to summary
protected transient int offset

Used in editing. Indicates x position to place editingComponent.

realEditorback to summary
protected TreeCellEditor realEditor

Editor handling the editing.

rendererback to summary
protected DefaultTreeCellRenderer renderer

Renderer, used to get border and offsets from.

timerback to summary
protected transient Timer timer

Used before starting the editing session.

treeback to summary
protected transient JTree tree

JTree instance listening too.

Constructor Detail

DefaultTreeCellEditorback to summary
public DefaultTreeCellEditor(JTree tree, DefaultTreeCellRenderer renderer)

Constructs a DefaultTreeCellEditor object for a JTree using the specified renderer and a default editor. (Use this constructor for normal editing.)

Parameters
tree:JTree

a JTree object

renderer:DefaultTreeCellRenderer

a DefaultTreeCellRenderer object

DefaultTreeCellEditorback to summary
public DefaultTreeCellEditor(JTree tree, DefaultTreeCellRenderer renderer, TreeCellEditor editor)

Constructs a DefaultTreeCellEditor object for a JTree using the specified renderer and the specified editor. (Use this constructor for specialized editing.)

Parameters
tree:JTree

a JTree object

renderer:DefaultTreeCellRenderer

a DefaultTreeCellRenderer object

editor:TreeCellEditor

a TreeCellEditor object

Method Detail

actionPerformedback to summary
public void actionPerformed(ActionEvent e)

Implements java.awt.event.ActionListener.actionPerformed.

Messaged when the timer fires, this will start the editing session.

addCellEditorListenerback to summary
public void addCellEditorListener(CellEditorListener l)

Implements javax.swing.CellEditor.addCellEditorListener.

Adds the CellEditorListener.

Parameters
l:CellEditorListener

the listener to be added

cancelCellEditingback to summary
public void cancelCellEditing()

Implements javax.swing.CellEditor.cancelCellEditing.

Messages cancelCellEditing to the realEditor and removes it from this instance.

canEditImmediatelyback to summary
protected boolean canEditImmediately(EventObject event)

Returns true if event is null, or it is a MouseEvent with a click count > 2 and inHitRegion returns true.

Parameters
event:EventObject

the event being studied

Returns:boolean

whether editing can be started for the given event

cleanupAfterEditingback to summary
private void cleanupAfterEditing()

Cleans up any state after editing has completed. Removes the editingComponent the editingContainer.

createContainerback to summary
protected Container createContainer()

Creates the container to manage placement of editingComponent.

Returns:Container

new Container object

createTreeCellEditorback to summary
protected TreeCellEditor createTreeCellEditor()

This is invoked if a TreeCellEditor is not supplied in the constructor. It returns a TextField editor.

Returns:TreeCellEditor

a new TextField editor

determineOffsetback to summary
protected void determineOffset(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row)

Determine the offset.

Parameters
tree:JTree

a JTree object

value:Object

a value

isSelected:boolean

selection status

expanded:boolean

expansion status

leaf:boolean

leaf status

row:int

current row

getBorderSelectionColorback to summary
public Color getBorderSelectionColor()

Returns the color the border is drawn.

Returns:Color

the border selection color

getCellEditorListenersback to summary
public CellEditorListener[] getCellEditorListeners()

Returns an array of all the CellEditorListeners added to this DefaultTreeCellEditor with addCellEditorListener().

Returns:CellEditorListener[]

all of the CellEditorListeners added or an empty array if no listeners have been added

Since
1.4
getCellEditorValueback to summary
public Object getCellEditorValue()

Implements javax.swing.CellEditor.getCellEditorValue.

Returns the value currently being edited.

Returns:Object

the value currently being edited

getFontback to summary
public Font getFont()

Gets the font used for editing.

Returns:Font

the editing Font

See Also
setFont
getTreeCellEditorComponentback to summary
public Component getTreeCellEditorComponent(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row)

Implements javax.swing.tree.TreeCellEditor.getTreeCellEditorComponent.

Configures the editor. Passed onto the realEditor.

inHitRegionback to summary
protected 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 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.

Parameters
x:int

the x-coordinate of the point

y:int

the y-coordinate of the point

Returns:boolean

true if the passed in location is a valid mouse location

isCellEditableback to summary
public boolean isCellEditable(EventObject event)

Implements javax.swing.CellEditor.isCellEditable.

If the realEditor returns true to this message, prepareForEditing is messaged and true is returned.

prepareForEditingback to summary
protected void prepareForEditing()

Invoked just before editing is to start. Will add the editingComponent to the editingContainer.

removeCellEditorListenerback to summary
public void removeCellEditorListener(CellEditorListener l)

Implements javax.swing.CellEditor.removeCellEditorListener.

Removes the previously added CellEditorListener.

Parameters
l:CellEditorListener

the listener to be removed

setBorderSelectionColorback to summary
public void setBorderSelectionColor(Color newColor)

Sets the color to use for the border.

Parameters
newColor:Color

the new border color

setFontback to summary
public void setFont(Font font)

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 instantiated with. If null for an editor was passed in a default editor will be created that will pick up this font.

Parameters
font:Font

the editing Font

See Also
getFont
setTreeback to summary
protected void setTree(JTree newTree)

Sets the tree currently editing for. This is needed to add a selection listener.

Parameters
newTree:JTree

the new tree to be edited

shouldSelectCellback to summary
public boolean shouldSelectCell(EventObject event)

Implements javax.swing.CellEditor.shouldSelectCell.

Messages the realEditor for the return value.

shouldStartEditingTimerback to summary
protected boolean shouldStartEditingTimer(EventObject event)

Returns true if event is a MouseEvent and the click count is 1.

Parameters
event:EventObject

the event being studied

Returns:boolean

whether event should starts the editing timer

startEditingTimerback to summary
protected void startEditingTimer()

Starts the editing timer.

stopCellEditingback to summary
public boolean stopCellEditing()

Implements javax.swing.CellEditor.stopCellEditing.

If the realEditor will allow editing to stop, the realEditor is removed and true is returned, otherwise false is returned.

valueChangedback to summary
public void valueChanged(TreeSelectionEvent e)

Implements javax.swing.event.TreeSelectionListener.valueChanged.

Resets lastPath.

javax.swing.tree back to summary

public Class DefaultTreeCellEditor.DefaultTextField

extends JTextField
Class Inheritance
Annotations
@SuppressWarnings:serial

TextField used when no editor is supplied. This textfield locks into the border it is constructed with. It also prefers its parents font over its font. And if the renderer is not null and no font has been specified the preferred height is that of the renderer.

Field Summary

Modifier and TypeField and Description
protected Border
Inherited from javax.swing.JTextField:
notifyAction

Constructor Summary

AccessConstructor and Description
public
DefaultTextField(Border
a Border object
border
)

Constructs a DefaultTreeCellEditor.DefaultTextField object.

Method Summary

Modifier and TypeMethod and Description
public Border
getBorder()

Overrides javax.swing.JComponent.getBorder.

Overrides JComponent.getBorder to returns the current border.

public Font
getFont()

Overrides java.awt.Component.getFont.

Implements java.awt.MenuContainer.getFont.

Gets the font of this component.

public Dimension

Returns:

a Dimension object containing the preferred size
getPreferredSize
()

Overrides javax.swing.JTextField.getPreferredSize.

Overrides JTextField.getPreferredSize to return the preferred size based on current font, if set, or else use renderer's font.

public void
setBorder(Border
the border to be rendered for this component
border
)

Overrides javax.swing.JComponent.setBorder.

Sets the border of this component.

Inherited from javax.swing.JTextField:
actionPropertyChangedaddActionListenerconfigurePropertiesFromActioncreateActionPropertyChangeListenercreateDefaultModelfireActionPerformedgetAccessibleContextgetActiongetActionListenersgetActionsgetColumnsgetColumnWidthgetHorizontalAlignmentgetHorizontalVisibilitygetScrollOffsetgetUIClassIDisValidateRootparamStringpostActionEventremoveActionListenerscrollRectToVisiblesetActionsetActionCommandsetColumnssetDocumentsetFontsetHorizontalAlignmentsetScrollOffset

Field Detail

borderback to summary
protected Border border

Hides javax.swing.JComponent.border.

Border to use.

Constructor Detail

DefaultTextFieldback to summary
public DefaultTextField(Border border)

Constructs a DefaultTreeCellEditor.DefaultTextField object.

Parameters
border:Border

a Border object

Since
1.4

Method Detail

getBorderback to summary
public Border getBorder()

Overrides javax.swing.JComponent.getBorder.

Overrides JComponent.getBorder to returns the current border.

getFontback to summary
public Font getFont()

Overrides java.awt.Component.getFont.

Implements java.awt.MenuContainer.getFont.

Doc from java.awt.Component.getFont.

Gets the font of this component.

getPreferredSizeback to summary
public Dimension getPreferredSize()

Overrides javax.swing.JTextField.getPreferredSize.

Overrides JTextField.getPreferredSize to return the preferred size based on current font, if set, or else use renderer's font.

Returns:Dimension

a Dimension object containing the preferred size

setBorderback to summary
public void setBorder(Border border)

Overrides javax.swing.JComponent.setBorder.

Sets the border of this component.

This is a bound property.

Parameters
border:Border

the border to be rendered for this component

Annotations
@BeanProperty
preferred:true
visualUpdate:true
description:The component\'s border.
See Also
Border, CompoundBorder
javax.swing.tree back to summary

public Class DefaultTreeCellEditor.EditorContainer

extends Container
Class Inheritance
Annotations
@SuppressWarnings:serial

Container responsible for placing the editingComponent.

Constructor Summary

AccessConstructor and Description
public
EditorContainer()

Constructs an EditorContainer object.

Method Summary

Modifier and TypeMethod and Description
private int
calculateIconY(Icon icon)

Calculate the y location for the icon.

public void
doLayout()

Overrides java.awt.Container.doLayout.

Lays out this Container.

public void
EditorContainer()

Do not use.

public Dimension

Returns:

a Dimension containing the preferred size for the Container; if editingComponent is null the Dimension returned is 0, 0
getPreferredSize
()

Overrides java.awt.Container.getPreferredSize.

Returns the preferred size for the Container.

public void
paint(Graphics g)

Overrides java.awt.Container.paint.

Overrides Container.paint to paint the node's icon and use the selection color for the background.

Inherited from java.awt.Container:
addaddaddaddaddaddContainerListeneraddImpladdNotifyaddPropertyChangeListeneraddPropertyChangeListenerapplyComponentOrientationareFocusTraversalKeysSetcountComponentsdeliverEventfindComponentAtfindComponentAtgetAlignmentXgetAlignmentYgetComponentgetComponentAtgetComponentAtgetComponentCountgetComponentsgetComponentZOrdergetContainerListenersgetFocusTraversalKeysgetFocusTraversalPolicygetInsetsgetLayoutgetListenersgetMaximumSizegetMinimumSizegetMousePositioninsetsinvalidateisAncestorOfisFocusCycleRootisFocusCycleRootisFocusTraversalPolicyProviderisFocusTraversalPolicySetisValidateRootlayoutlistlistlocateminimumSizepaintComponentsparamStringpreferredSizeprintprintComponentsprocessContainerEventprocessEventremoveremoveremoveAllremoveContainerListenerremoveNotifysetComponentZOrdersetFocusCycleRootsetFocusTraversalKeyssetFocusTraversalPolicysetFocusTraversalPolicyProvidersetFontsetLayouttransferFocusDownCycleupdatevalidatevalidateTree

Constructor Detail

EditorContainerback to summary
public EditorContainer()

Constructs an EditorContainer object.

Method Detail

calculateIconYback to summary
private int calculateIconY(Icon icon)

Calculate the y location for the icon.

doLayoutback to summary
public void doLayout()

Overrides java.awt.Container.doLayout.

Lays out this Container. If editing, the editor will be placed at offset in the x direction and 0 for y.

EditorContainerback to summary
public void EditorContainer()

Do not use.

getPreferredSizeback to summary
public Dimension getPreferredSize()

Overrides java.awt.Container.getPreferredSize.

Returns the preferred size for the Container. This will be at least preferred size of the editor plus offset.

Returns:Dimension

a Dimension containing the preferred size for the Container; if editingComponent is null the Dimension returned is 0, 0

paintback to summary
public void paint(Graphics g)

Overrides java.awt.Container.paint.

Overrides Container.paint to paint the node's icon and use the selection color for the background.