public class DefaultTreeCellEditor extends Object implements ActionListener, TreeCellEditor, TreeSelectionListener
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 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 XMLEncoder
.
JTree
Modifier and Type | Class and Description |
---|---|
class |
DefaultTreeCellEditor.DefaultTextField
|
class |
DefaultTreeCellEditor.EditorContainer Container responsible for placing the |
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 transient 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 transient int offset
Used in editing. Indicates x position to place editingComponent
.
protected transient JTree tree
JTree
instance listening too.
protected transient TreePath lastPath
Last path that was selected.
protected transient Timer timer
Used before starting the editing session.
protected transient int lastRow
Row that was last passed into getTreeCellEditorComponent
.
protected Color borderSelectionColor
True if the border selection color should be drawn.
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.
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.)
tree
- a JTree
objectrenderer
- a DefaultTreeCellRenderer
objectpublic 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.)
tree
- a JTree
objectrenderer
- a DefaultTreeCellRenderer
objecteditor
- a TreeCellEditor
objectpublic void setBorderSelectionColor(Color newColor)
Sets the color to use for the border.
newColor
- the new border colorpublic Color getBorderSelectionColor()
Returns the color the border is drawn.
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.
font
- the editing Font
getFont()
public Font getFont()
Gets the font used for editing.
Font
setFont(java.awt.Font)
public Component getTreeCellEditorComponent(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row)
Configures the editor. Passed onto the realEditor
.
getTreeCellEditorComponent
in interface TreeCellEditor
tree
- the JTree that is asking the editor to edit; this parameter can be nullvalue
- the value of the cell to be editedisSelected
- true if the cell is to be rendered with selection highlightingexpanded
- true if the node is expandedleaf
- true if the node is a leaf noderow
- the row index of the node being editedpublic Object getCellEditorValue()
Returns the value currently being edited.
getCellEditorValue
in interface CellEditor
public boolean isCellEditable(EventObject event)
If the realEditor
returns true to this message, prepareForEditing
is messaged and true is returned.
isCellEditable
in interface CellEditor
event
- the event the editor should use to consider whether to begin editing or notCellEditor.shouldSelectCell(java.util.EventObject)
public boolean shouldSelectCell(EventObject event)
Messages the realEditor
for the return value.
shouldSelectCell
in interface CellEditor
event
- the event the editor should use to start editingCellEditor.isCellEditable(java.util.EventObject)
public boolean stopCellEditing()
If the realEditor
will allow editing to stop, the realEditor
is removed and true is returned, otherwise false is returned.
stopCellEditing
in interface CellEditor
public void cancelCellEditing()
Messages cancelCellEditing
to the realEditor
and removes it from this instance.
cancelCellEditing
in interface CellEditor
public void addCellEditorListener(CellEditorListener l)
Adds the CellEditorListener
.
addCellEditorListener
in interface CellEditor
l
- the listener to be addedpublic void removeCellEditorListener(CellEditorListener l)
Removes the previously added CellEditorListener
.
removeCellEditorListener
in interface CellEditor
l
- the listener to be removedpublic CellEditorListener[] getCellEditorListeners()
Returns an array of all the CellEditorListener
s added to this DefaultTreeCellEditor with addCellEditorListener().
CellEditorListener
s added or an empty array if no listeners have been addedpublic void valueChanged(TreeSelectionEvent e)
Resets lastPath
.
valueChanged
in interface TreeSelectionListener
e
- the event that characterizes the change.public void actionPerformed(ActionEvent e)
Messaged when the timer fires, this will start the editing session.
actionPerformed
in interface ActionListener
protected void setTree(JTree newTree)
Sets the tree currently editing for. This is needed to add a selection listener.
newTree
- the new tree to be editedprotected boolean shouldStartEditingTimer(EventObject event)
Returns true if event
is a MouseEvent
and the click count is 1.
event
- the event being studiedprotected void startEditingTimer()
Starts the editing timer.
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.
event
- the event being studiedprotected 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.
x
- the x-coordinate of the pointy
- the y-coordinate of the pointprotected void determineOffset(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row)
protected void prepareForEditing()
Invoked just before editing is to start. Will add the editingComponent
to the editingContainer
.
protected Container createContainer()
Creates the container to manage placement of editingComponent
.
protected TreeCellEditor createTreeCellEditor()
This is invoked if a TreeCellEditor
is not supplied in the constructor. It returns a TextField
editor.
TextField
editor
© 1993–2017, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.