Class SpinnerCellEditor
java.lang.Object
javax.swing.AbstractCellEditor
jmt.framework.gui.table.editors.SpinnerCellEditor
- All Implemented Interfaces:
Serializable, CellEditor, TableCellEditor, TableCellRenderer
public class SpinnerCellEditor
extends AbstractCellEditor
implements TableCellEditor, CellEditor, TableCellRenderer
Title: Spinner Table CellViewer/CellEditor
Description: A component to display a Spinner as both a viewer and an editor in a table. Internally caches already allocated editors to avoid creation of too many Spinners. Renderer instance is a single element cached too.
- Author:
- Leran Chen 05/08/2021
- See Also:
-
Field Summary
FieldsFields inherited from class AbstractCellEditor
changeEvent, listenerList -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedSpinnerCellEditor(Integer num, Integer maxvalue) Creates a new Spinner editor or renderer basing on given number -
Method Summary
Modifier and TypeMethodDescriptionvoidaddChangeListener(ChangeListener changeListener) Returns the value contained in the editor.static SpinnerCellEditorgetEditorInstance(Integer num) Returns a new instance of CellEditor that will display number in a Spinnerstatic SpinnerCellEditorgetEditorInstance(Integer num, Integer maxvalue) static SpinnerCellEditorReturns a new instance of CellRenderer that will display current number in a SpinnergetTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) Sets an initialvaluefor the editor.getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) Returns the component used for drawing the cell.Methods inherited from class AbstractCellEditor
addCellEditorListener, cancelCellEditing, fireEditingCanceled, fireEditingStopped, getCellEditorListeners, isCellEditable, removeCellEditorListener, shouldSelectCell, stopCellEditingMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface CellEditor
addCellEditorListener, cancelCellEditing, isCellEditable, removeCellEditorListener, shouldSelectCell, stopCellEditing
-
Field Details
-
spinner
-
renderer
-
-
Constructor Details
-
SpinnerCellEditor
-
-
Method Details
-
getEditorInstance
Returns a new instance of CellEditor that will display number in a Spinner- Parameters:
num- number to be displayed from the Spinner- Returns:
- CellEditor created
-
getEditorInstance
-
getRendererInstance
Returns a new instance of CellRenderer that will display current number in a Spinner- Returns:
- cached CellRenderer
-
getCellEditorValue
Returns the value contained in the editor.- Specified by:
getCellEditorValuein interfaceCellEditor- Returns:
- the value contained in the editor
-
getTableCellEditorComponent
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) Sets an initialvaluefor the editor. This will cause the editor tostopEditingand 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
Componenthierarchy. Once installed in the client's hierarchy this component will then be able to draw and receive user input.- Specified by:
getTableCellEditorComponentin interfaceTableCellEditor- Parameters:
table- theJTablethat is asking the editor to edit; can benullvalue- 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.nullis 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
-
addChangeListener
-
getTableCellRendererComponent
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) Returns the component used for drawing the cell. This method is used to configure the renderer appropriately before drawing.- Specified by:
getTableCellRendererComponentin interfaceTableCellRenderer- Parameters:
table- theJTablethat is asking the renderer to draw; can benullvalue- the value of the cell to be rendered. It is up to the specific renderer to interpret and draw the value. For example, ifvalueis the string "true", it could be rendered as a string or it could be rendered as a check box that is checked.nullis a valid valueisSelected- true if the cell is to be rendered with the selection highlighted; false otherwisehasFocus- if true, render cell appropriately. For example, put a special border on the cell, if the cell can be edited, render in the color used to indicate editingrow- the row index of the cell being drawn. When drawing the header, the value ofrowis -1column- the column index of the cell being drawn
-