- All Implemented Interfaces:
Serializable,CellEditor,TableCellEditor,TreeCellEditor
Base class for custom text-based table-cell editors in which
a cell's value can be created using an
InternationalFormatter.
An InternationalFormatter can create dates, times, and numbers.
To use this class, the methods getFormat(),
getFormatter() and
convertObject(Object) must be implement:
getFormatter()provides a subclass ofInternationalFormatterthat will format text strings to produce a desired object. This method is called once in the constructor.getFormat()will provide a format that programs the formatter returned bygetFormatter(). This method is called once in the constructor.convertObject(Object)converts the value of the text field used by a cell into an object of the desired type.
This class is based on the example provided in a Java tutorial. That link includes a copyright and permission to use/modify that example. This class generalizes that example.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classIndicates that object conversion failed, so fall back to using the parser.Nested classes/interfaces inherited from class javax.swing.DefaultCellEditor
DefaultCellEditor.EditorDelegate -
Field Summary
Fields inherited from class javax.swing.DefaultCellEditor
clickCountToStart, delegate, editorComponentFields inherited from class javax.swing.AbstractCellEditor
changeEvent, listenerList -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected intReturn the alignment for text.protected abstract ObjectConvert an object to the correct type for a cell.Returns the value contained in this editor.protected abstract FormatGet the format used to parse the string representation for the object in the cells handled by this cell editor.protected abstract InternationalFormatterGet the formatter for this object.getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) Sets an initial value for the editor.getTreeCellEditorComponent(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row) protected abstract StringMessage to use if the new value for a cell is not valid.booleanMethods inherited from class javax.swing.DefaultCellEditor
cancelCellEditing, getClickCountToStart, getComponent, isCellEditable, setClickCountToStart, shouldSelectCellMethods inherited from class javax.swing.AbstractCellEditor
addCellEditorListener, fireEditingCanceled, fireEditingStopped, getCellEditorListeners, removeCellEditorListenerMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface javax.swing.CellEditor
addCellEditorListener, removeCellEditorListener
-
Constructor Details
-
ITextCellEditor
public ITextCellEditor()Constructor.
-
-
Method Details
-
getFormat
Get the format used to parse the string representation for the object in the cells handled by this cell editor.- Returns:
- the format
-
alignment
protected int alignment()Return the alignment for text. Valid values areSwingConstants.LEFT,SwingConstants.CENTERSwingConstants.RIGHT,SwingConstants.LEADING(the default), orSwingConstants.TRAILING.- Returns:
- the alignment constant
-
getFormatter
Get the formatter for this object. The formatter will be configured by this object's constructor to use the format returned bygetFormat().- Returns:
- the formatter
-
convertObject
Convert an object to the correct type for a cell. An instance ofInputTablePaneassigns an object type to each column. In case editing a cell creates a different type, this class can be used to convert that type to the desired one. For example, a database application may want table entries to be instances of java.sql.Date. If the object o ends up as an instance ofDate, it can be easily converted to java.sql.Date by the expressionnew java.sql.Date(((java.util.Date)o).getTime()).- Parameters:
o- the object- Returns:
- the converted object
- Throws:
ITextCellEditor.NoConvertException- if the argument cannot be converted to the desired type
-
revertMessage
Message to use if the new value for a cell is not valid. For example, if the value must be a date using a specific date format, this message might be "The value must be a date specified by <br> the format MM/DD/YYYY"Each line of the message should be about 40 characters long except for the last line. The message is treated as an HTML fragment.
- Returns:
- the message string
-
getTableCellEditorComponent
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) Sets an initial value for the editor. This will cause the editor to stopEditing and lose any partially edited value if the editor is editing when this method is called.Returns the component that should be added to the client's Component hierarchy. Once installed in the client's hierarchy this component will then be able to draw and receive user input.
Note: this description was copied from the documentation for
TableCellEditor.- Specified by:
getTableCellEditorComponentin interfaceTableCellEditor- Overrides:
getTableCellEditorComponentin classTextCellEditor<Object>- Parameters:
table- the JTable that is asking the editor to edit; can be nullvalue- 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 valueisSelected- true if the cell is to be rendered with highlightingrow- the row of the cell being editedcolumn- the column of the cell being edited- Returns:
- the component for editing
-
getTreeCellEditorComponent
public Component getTreeCellEditorComponent(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row) - Specified by:
getTreeCellEditorComponentin interfaceTreeCellEditor- Overrides:
getTreeCellEditorComponentin classTextCellEditor<Object>
-
getCellEditorValue
Returns the value contained in this editor.- Specified by:
getCellEditorValuein interfaceCellEditor- Overrides:
getCellEditorValuein classTextCellEditor<Object>- Returns:
- the value contained in this editor
-
stopCellEditing
public boolean stopCellEditing()- Specified by:
stopCellEditingin interfaceCellEditor- Overrides:
stopCellEditingin classTextCellEditor<Object>
-