Top Description Inners Fields Constructors Methods
javax.swing

public Class DefaultCellEditor

extends AbstractCellEditor
implements TableCellEditor, TreeCellEditor
Class Inheritance
All Implemented Interfaces
javax.swing.tree.TreeCellEditor, javax.swing.CellEditor, javax.swing.table.TableCellEditor
Known Direct Subclasses
javax.swing.JTable.GenericEditor, javax.swing.JTable.BooleanEditor, sun.swing.FilePane.DetailsTableCellEditor
Annotations
@SuppressWarnings:serial
Imports
java.awt.Component, java.awt.event.*, java.beans.ConstructorProperties, java.lang.Boolean, javax.swing.table.*, javax.swing.event.*, java.util.EventObject, javax.swing.tree.*, java.io.Serializable

The default editor for table and tree cells.

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.

Authors
Alan Chung, Philip Milne
Since
1.2

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected class
DefaultCellEditor.EditorDelegate

The protected EditorDelegate class.

Field Summary

Modifier and TypeField and Description
protected int
clickCountToStart

An integer specifying the number of clicks needed to start editing.

protected DefaultCellEditor.EditorDelegate
delegate

The delegate class which handles all methods sent from the CellEditor.

protected JComponent
editorComponent

The Swing component being edited.

Inherited from javax.swing.AbstractCellEditor:
changeEventlistenerList

Constructor Summary

AccessConstructor and Description
public
DefaultCellEditor(final JTextField
a JTextField object
textField
)

Constructs a DefaultCellEditor that uses a text field.

public
DefaultCellEditor(final JCheckBox
a JCheckBox object
checkBox
)

Constructs a DefaultCellEditor object that uses a check box.

public
DefaultCellEditor(final JComboBox<?>
a JComboBox object
comboBox
)

Constructs a DefaultCellEditor object that uses a combo box.

Method Summary

Modifier and TypeMethod and Description
public void
cancelCellEditing()

Overrides javax.swing.AbstractCellEditor.cancelCellEditing.

Implements javax.swing.CellEditor.cancelCellEditing.

Forwards the message from the CellEditor to the delegate.
public Object
getCellEditorValue()

Implements javax.swing.CellEditor.getCellEditorValue.

Forwards the message from the CellEditor to the delegate.
public int

Returns:

the number of clicks needed to start editing
getClickCountToStart
()

Returns the number of clicks needed to start editing.

public Component

Returns:

the editor Component
getComponent
()

Returns a reference to the editor component.

public Component
getTableCellEditorComponent(JTable
the JTable that is asking the editor to edit; can be null
table
,
Object
the value of the cell to be edited; it is up to the specific editor to interpret and draw the value. For example, if value is the string "true", it could be rendered as a string or it could be rendered as a check box that is checked. null is a valid value
value
,
boolean
true if the cell is to be rendered with highlighting
isSelected
,
int
the row of the cell being edited
row
,
int
the column of the cell being edited
column
)

Implements javax.swing.table.TableCellEditor.getTableCellEditorComponent.

Implements the TableCellEditor interface.
public Component
getTreeCellEditorComponent(JTree
the JTree that is asking the editor to edit; this parameter can be null
tree
,
Object
the value of the cell to be edited
value
,
boolean
true if the cell is to be rendered with selection highlighting
isSelected
,
boolean
true if the node is expanded
expanded
,
boolean
true if the node is a leaf node
leaf
,
int
the row index of the node being edited
row
)

Implements javax.swing.tree.TreeCellEditor.getTreeCellEditorComponent.

Implements the TreeCellEditor interface.
public boolean
isCellEditable(EventObject
the event the editor should use to consider whether to begin editing or not
anEvent
)

Overrides javax.swing.AbstractCellEditor.isCellEditable.

Implements javax.swing.CellEditor.isCellEditable.

Forwards the message from the CellEditor to the delegate.
public void
setClickCountToStart(int
an int specifying the number of clicks needed to start editing
count
)

Specifies the number of clicks needed to start editing.

public boolean
shouldSelectCell(EventObject
the event the editor should use to start editing
anEvent
)

Overrides javax.swing.AbstractCellEditor.shouldSelectCell.

Implements javax.swing.CellEditor.shouldSelectCell.

Forwards the message from the CellEditor to the delegate.
public boolean
stopCellEditing()

Overrides javax.swing.AbstractCellEditor.stopCellEditing.

Implements javax.swing.CellEditor.stopCellEditing.

Forwards the message from the CellEditor to the delegate.
Inherited from javax.swing.AbstractCellEditor:
addCellEditorListenerfireEditingCanceledfireEditingStoppedgetCellEditorListenersremoveCellEditorListener

Field Detail

clickCountToStartback to summary
protected int clickCountToStart

An integer specifying the number of clicks needed to start editing. Even if clickCountToStart is defined as zero, it will not initiate until a click occurs.

delegateback to summary
protected DefaultCellEditor.EditorDelegate delegate

The delegate class which handles all methods sent from the CellEditor.

editorComponentback to summary
protected JComponent editorComponent

The Swing component being edited.

Constructor Detail

DefaultCellEditorback to summary
public DefaultCellEditor(final JTextField textField)

Constructs a DefaultCellEditor that uses a text field.

Parameters
textField:JTextField

a JTextField object

Annotations
@ConstructorProperties:component
DefaultCellEditorback to summary
public DefaultCellEditor(final JCheckBox checkBox)

Constructs a DefaultCellEditor object that uses a check box.

Parameters
checkBox:JCheckBox

a JCheckBox object

DefaultCellEditorback to summary
public DefaultCellEditor(final JComboBox<?> comboBox)

Constructs a DefaultCellEditor object that uses a combo box.

Parameters
comboBox:JComboBox<?>

a JComboBox object

Method Detail

cancelCellEditingback to summary
public void cancelCellEditing()

Overrides javax.swing.AbstractCellEditor.cancelCellEditing.

Implements javax.swing.CellEditor.cancelCellEditing.

Forwards the message from the CellEditor to the delegate.

See Also
EditorDelegate#cancelCellEditing
getCellEditorValueback to summary
public Object getCellEditorValue()

Implements javax.swing.CellEditor.getCellEditorValue.

Forwards the message from the CellEditor to the delegate.

Returns:Object

Doc from javax.swing.CellEditor.getCellEditorValue.

the value contained in the editor

See Also
EditorDelegate#getCellEditorValue
getClickCountToStartback to summary
public int getClickCountToStart()

Returns the number of clicks needed to start editing.

Returns:int

the number of clicks needed to start editing

getComponentback to summary
public Component getComponent()

Returns a reference to the editor component.

Returns:Component

the editor Component

getTableCellEditorComponentback to summary
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column)

Implements javax.swing.table.TableCellEditor.getTableCellEditorComponent.

Implements the TableCellEditor interface.

Parameters
table:JTable

Doc from javax.swing.table.TableCellEditor.getTableCellEditorComponent.

the JTable that is asking the editor to edit; can be null

value:Object

Doc from javax.swing.table.TableCellEditor.getTableCellEditorComponent.

the value of the cell to be edited; it is up to the specific editor to interpret and draw the value. For example, if value is the string "true", it could be rendered as a string or it could be rendered as a check box that is checked. null is a valid value

isSelected:boolean

Doc from javax.swing.table.TableCellEditor.getTableCellEditorComponent.

true if the cell is to be rendered with highlighting

row:int

Doc from javax.swing.table.TableCellEditor.getTableCellEditorComponent.

the row of the cell being edited

column:int

Doc from javax.swing.table.TableCellEditor.getTableCellEditorComponent.

the column of the cell being edited

Returns:Component

Doc from javax.swing.table.TableCellEditor.getTableCellEditorComponent.

the component for editing

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

Implements javax.swing.tree.TreeCellEditor.getTreeCellEditorComponent.

Implements the TreeCellEditor interface.

Parameters
tree:JTree

Doc from javax.swing.tree.TreeCellEditor.getTreeCellEditorComponent.

the JTree that is asking the editor to edit; this parameter can be null

value:Object

Doc from javax.swing.tree.TreeCellEditor.getTreeCellEditorComponent.

the value of the cell to be edited

isSelected:boolean

Doc from javax.swing.tree.TreeCellEditor.getTreeCellEditorComponent.

true if the cell is to be rendered with selection highlighting

expanded:boolean

Doc from javax.swing.tree.TreeCellEditor.getTreeCellEditorComponent.

true if the node is expanded

leaf:boolean

Doc from javax.swing.tree.TreeCellEditor.getTreeCellEditorComponent.

true if the node is a leaf node

row:int

Doc from javax.swing.tree.TreeCellEditor.getTreeCellEditorComponent.

the row index of the node being edited

Returns:Component

Doc from javax.swing.tree.TreeCellEditor.getTreeCellEditorComponent.

the component for editing

isCellEditableback to summary
public boolean isCellEditable(EventObject anEvent)

Overrides javax.swing.AbstractCellEditor.isCellEditable.

Implements javax.swing.CellEditor.isCellEditable.

Forwards the message from the CellEditor to the delegate.

Parameters
anEvent:EventObject

Doc from javax.swing.CellEditor.isCellEditable.

the event the editor should use to consider whether to begin editing or not

Returns:boolean

Doc from javax.swing.CellEditor.isCellEditable.

true if editing can be started

See Also
EditorDelegate#isCellEditable(EventObject)
setClickCountToStartback to summary
public void setClickCountToStart(int count)

Specifies the number of clicks needed to start editing.

Parameters
count:int

an int specifying the number of clicks needed to start editing

See Also
getClickCountToStart
shouldSelectCellback to summary
public boolean shouldSelectCell(EventObject anEvent)

Overrides javax.swing.AbstractCellEditor.shouldSelectCell.

Implements javax.swing.CellEditor.shouldSelectCell.

Forwards the message from the CellEditor to the delegate.

Parameters
anEvent:EventObject

Doc from javax.swing.CellEditor.shouldSelectCell.

the event the editor should use to start editing

Returns:boolean

Doc from javax.swing.CellEditor.shouldSelectCell.

true if the editor would like the editing cell to be selected; otherwise returns false

See Also
EditorDelegate#shouldSelectCell(EventObject)
stopCellEditingback to summary
public boolean stopCellEditing()

Overrides javax.swing.AbstractCellEditor.stopCellEditing.

Implements javax.swing.CellEditor.stopCellEditing.

Forwards the message from the CellEditor to the delegate.

Returns:boolean

Doc from javax.swing.CellEditor.stopCellEditing.

true if editing was stopped; false otherwise

See Also
EditorDelegate#stopCellEditing
javax.swing back to summary

protected Class DefaultCellEditor.EditorDelegate

extends Object
implements ActionListener, ItemListener, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, java.awt.event.ItemListener, java.util.EventListener, java.awt.event.ActionListener

The protected EditorDelegate class.

Field Summary

Modifier and TypeField and Description
protected Object
value

The value of this cell.

Constructor Summary

AccessConstructor and Description
protected
EditorDelegate()

Constructs an EditorDelegate.

Method Summary

Modifier and TypeMethod and Description
public void
actionPerformed(ActionEvent
the action event
e
)

Implements java.awt.event.ActionListener.actionPerformed.

When an action is performed, editing is ended.
public void
cancelCellEditing()

Cancels editing.

public Object

Returns:

the value of this cell
getCellEditorValue
()

Returns the value of this cell.

public boolean

Returns:

true if cell is ready for editing, false otherwise
isCellEditable
(EventObject
the event
anEvent
)

Returns true if anEvent is not a MouseEvent.

public void
itemStateChanged(ItemEvent
the action event
e
)

Implements java.awt.event.ItemListener.itemStateChanged.

When an item's state changes, editing is ended.
public void
setValue(Object
the new value of this cell
value
)

Sets the value of this cell.

public boolean

Returns:

true
shouldSelectCell
(EventObject
the event
anEvent
)

Returns true to indicate that the editing cell may be selected.

public boolean

Returns:

true to indicate editing has begun
startCellEditing
(EventObject
the event
anEvent
)

Returns true to indicate that editing has begun.

public boolean

Returns:

true
stopCellEditing
()

Stops editing and returns true to indicate that editing has stopped.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

valueback to summary
protected Object value

The value of this cell.

Constructor Detail

EditorDelegateback to summary
protected EditorDelegate()

Constructs an EditorDelegate.

Method Detail

actionPerformedback to summary
public void actionPerformed(ActionEvent e)

Implements java.awt.event.ActionListener.actionPerformed.

When an action is performed, editing is ended.

Parameters
e:ActionEvent

the action event

See Also
stopCellEditing
cancelCellEditingback to summary
public void cancelCellEditing()

Cancels editing. This method calls fireEditingCanceled.

getCellEditorValueback to summary
public Object getCellEditorValue()

Returns the value of this cell.

Returns:Object

the value of this cell

isCellEditableback to summary
public boolean isCellEditable(EventObject anEvent)

Returns true if anEvent is not a MouseEvent. Otherwise, it returns true if the necessary number of clicks have occurred, and returns false otherwise.

Parameters
anEvent:EventObject

the event

Returns:boolean

true if cell is ready for editing, false otherwise

See Also
setClickCountToStart, shouldSelectCell
itemStateChangedback to summary
public void itemStateChanged(ItemEvent e)

Implements java.awt.event.ItemListener.itemStateChanged.

When an item's state changes, editing is ended.

Parameters
e:ItemEvent

the action event

See Also
stopCellEditing
setValueback to summary
public void setValue(Object value)

Sets the value of this cell.

Parameters
value:Object

the new value of this cell

shouldSelectCellback to summary
public boolean shouldSelectCell(EventObject anEvent)

Returns true to indicate that the editing cell may be selected.

Parameters
anEvent:EventObject

the event

Returns:boolean

true

See Also
isCellEditable
startCellEditingback to summary
public boolean startCellEditing(EventObject anEvent)

Returns true to indicate that editing has begun.

Parameters
anEvent:EventObject

the event

Returns:boolean

true to indicate editing has begun

stopCellEditingback to summary
public boolean stopCellEditing()

Stops editing and returns true to indicate that editing has stopped. This method calls fireEditingStopped.

Returns:boolean

true