Class NumberEditorExt
java.lang.Object
javax.swing.AbstractCellEditor
javax.swing.DefaultCellEditor
org.jdesktop.swingx.table.NumberEditorExt
- All Implemented Interfaces:
Serializable, CellEditor, TableCellEditor, TreeCellEditor
Issue #393-swingx: localized NumberEditor. Added feature to use StrictNumberFormatter.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class DefaultCellEditor
DefaultCellEditor.EditorDelegate -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static Class<?>[](package private) Constructor<?> private booleanFields inherited from class DefaultCellEditor
clickCountToStart, delegate, editorComponentFields inherited from class AbstractCellEditor
changeEvent, listenerList -
Constructor Summary
ConstructorsConstructorDescriptionInstantiates an editor with default NumberFormat and default NumberFormatter.NumberEditorExt(boolean useStrictFormatter) Instantiates an editor with default NumberFormat and NumberFormatter depending on useStrictFormatter.NumberEditorExt(NumberFormat format) Instantiates an editor with the given NumberFormat and default NumberFormatter.NumberEditorExt(NumberFormat format, boolean useStrictFormatter) Instantiates an editor with the given NumberFormat and NumberFormatter depending on useStrictFormatter. -
Method Summary
Modifier and TypeMethodDescriptionprivate static JFormattedTextFieldcreateFormattedTextField(NumberFormat formatter) Creates and returns a JFormattedTextField configured with defaults.private static JFormattedTextFieldCreates and returns a JFormattedTextField configured with SwingX extended NumberFormat and StrictNumberFormatter.protected NumberReturns the editor value as number.getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) Override and set the border back to normal in case there was an error previouslyprotected booleanprotected booleanisValid()Returns a boolean indicating whether the current text is valid for instantiating the expected Number type.booleanMethods inherited from class DefaultCellEditor
cancelCellEditing, getClickCountToStart, getTreeCellEditorComponent, isCellEditable, setClickCountToStart, shouldSelectCellMethods inherited from class AbstractCellEditor
addCellEditorListener, fireEditingCanceled, fireEditingStopped, getCellEditorListeners, removeCellEditorListenerMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface CellEditor
addCellEditorListener, removeCellEditorListener
-
Field Details
-
argTypes
-
constructor
Constructor<?> constructor -
useStrictFormatter
private boolean useStrictFormatter
-
-
Constructor Details
-
NumberEditorExt
public NumberEditorExt()Instantiates an editor with default NumberFormat and default NumberFormatter. -
NumberEditorExt
Instantiates an editor with the given NumberFormat and default NumberFormatter.- Parameters:
format- the NumberFormat to use for conversion, may be null to indicate usage of default NumberFormat.
-
NumberEditorExt
public NumberEditorExt(boolean useStrictFormatter) Instantiates an editor with default NumberFormat and NumberFormatter depending on useStrictFormatter.- Parameters:
useStrictFormatter- if true, uses a StrictNumberFormatter, else uses default NumberFormatter
-
NumberEditorExt
Instantiates an editor with the given NumberFormat and NumberFormatter depending on useStrictFormatter.- Parameters:
format- the NumberFormat to use for conversion, may be null to indicate usage of default NumberFormatuseStrictFormatter- if true, uses a StrictNumberFormatter, else uses default NumberFormatter
-
-
Method Details
-
stopCellEditing
public boolean stopCellEditing()- Specified by:
stopCellEditingin interfaceCellEditor- Overrides:
stopCellEditingin classDefaultCellEditor
-
isValid
protected boolean isValid()Returns a boolean indicating whether the current text is valid for instantiating the expected Number type.- Returns:
- true if text is valid, false otherwise.
-
getNumber
Returns the editor value as number. May fail for a variety of reasons, as it forces parsing of the current text as well as reflective construction of the target type.- Returns:
- the editor value or null
- Throws:
Exception- if creation of the expected type fails in some way.
-
hasStrictFormatter
protected boolean hasStrictFormatter()- Returns:
-
getTableCellEditorComponent
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) Override and set the border back to normal in case there was an error previously- Specified by:
getTableCellEditorComponentin interfaceTableCellEditor- Overrides:
getTableCellEditorComponentin classDefaultCellEditor
-
getCellEditorValue
Overridden to instantiate a Number of the expected type. Note that this may throw a IllegalStateException if invoked without querying for a valid value with stopCellEditing. This should not happen during normal usage.
- Specified by:
getCellEditorValuein interfaceCellEditor- Overrides:
getCellEditorValuein classDefaultCellEditor- Throws:
IllegalStateException- if current value invalid
-
getComponent
Convenience override with type cast.
- Overrides:
getComponentin classDefaultCellEditor
-
createFormattedTextFieldX
Creates and returns a JFormattedTextField configured with SwingX extended NumberFormat and StrictNumberFormatter. This method is called if the constructor parameter useStrictFormatter is true. Use a static method so that we can do some stuff before calling the superclass. -
createFormattedTextField
Creates and returns a JFormattedTextField configured with defaults. This method is called if the contructor useStrictFormatter is false.Use a static method so that we can do some stuff before calling the superclass.
-