java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
org.bzdev.swing.InputTablePane
- All Implemented Interfaces:
ImageObserver
,MenuContainer
,Serializable
,Accessible
Table pane for inputing data.
This class creates a JPanel containing a JTable plus some controls.
The class
InputTablePane.ColSpec
specifies each column in
the table, indicating a title, how the cells in the column are rendered,
and how the cells in the column are edited (a null editor indicates that
the column is a read-only column).
There are methods for determining the number of rows and columns in the table and for obtaining the values at any given cell, and to create dialog boxes containing this panel or a new instance of this panel.
The table model for this panel's table is initialized by providing a
Vector
whose type is
Vector<Vector<Object>>, with the Vector<Object>
representing the rows.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Specification for a table column.Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
The value returned byshowDialog(Component,String,InputTablePane)
when the dialog's CANCEL button is pressed.static final DefaultCellEditor
Table-cell editor that indicates that a table's default should be used.static final int
The value returned byshowDialog(Component,String,InputTablePane)
when the dialog's OK button is pressed.Fields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
Fields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
-
Constructor Summary
ConstructorsConstructorDescriptionInputTablePane
(InputTablePane.ColSpec[] colspec, int nrows, boolean canAdd, boolean canDel, boolean canMove) Constructor.InputTablePane
(InputTablePane.ColSpec[] colspec, int nrows, Vector<Vector<Object>> initialRows, boolean canAdd, boolean canDel, boolean canMove) Constructor with explicitly provided rows, possibly followed by blank rows.InputTablePane
(InputTablePane.ColSpec[] colspec, Vector<Vector<Object>> rows, boolean canAdd, boolean canDel, boolean canMove) Constructor based on explicitly provided rows. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a listener to the list that is notified each time a change to the underlying table's data model occurs.protected void
beforeRowDeletion
(int row) Indicate that a row is about to be deletedint
Get the number of columns in the table.protected TableCellEditor
getCustomEditor
(JTable tbl, int i, int j) Get a custom cell editor for a specific row and column.protected TableCellRenderer
getCustomRenderer
(JTable tbl, int i, int j) Get a custom table-cell renderer for a specific row and column.int
Get the number of rows in the table.getValueAt
(int rowIndex, int columnIndex) Get the value of a table cell for this table.protected int
minimumSelectableRow
(int col, boolean allColumnSelection) Limit the range of rows that are selectable for a given column.protected boolean
prohibitEditing
(int row, int col) Prevent editing of specific rows and columns.void
Removes a listener from the list that is notified each time a change to the underlying table's data model occurs.void
setValueAt
(Object val, int row, int col) Set the valoue of a table cell for this table.static int
showDialog
(Component parent, String title, InputTablePane ipane) Show a dialog containing an InputTablePanestatic InputTablePane
showDialog
(Component parent, String title, InputTablePane.ColSpec[] colspec, int nrows, boolean canAdd, boolean canDel, boolean canMove) Create a new InputTablePane inside a dialog.static InputTablePane
showDialog
(Component parent, String title, InputTablePane.ColSpec[] colspec, int nrows, Vector<Vector<Object>> initialRows, boolean canAdd, boolean canDel, boolean canMove) Create a new InputTablePane, initializing some rows, placing the table inside a dialog.static InputTablePane
showDialog
(Component parent, String title, InputTablePane.ColSpec[] colspec, Vector<Vector<Object>> initialRows, boolean canAdd, boolean canDel, boolean canMove) Create a new InputTablePane, initializing some rows, placing the table inside a dialog.void
Stop editing a cell.Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Field Details
-
DEFAULT_CELL_EDITOR
Table-cell editor that indicates that a table's default should be used. This should be used only with an instance ofInputTablePane
. -
OK
public static final int OKThe value returned byshowDialog(Component,String,InputTablePane)
when the dialog's OK button is pressed.- See Also:
-
CANCEL
public static final int CANCELThe value returned byshowDialog(Component,String,InputTablePane)
when the dialog's CANCEL button is pressed.- See Also:
-
-
Constructor Details
-
InputTablePane
public InputTablePane(InputTablePane.ColSpec[] colspec, int nrows, boolean canAdd, boolean canDel, boolean canMove) Constructor.- Parameters:
colspec
- an array (one entry per column in column order) specifying a columnnrows
- the number of rowscanAdd
- true if rows can be added to the table; false otherwisecanDel
- true if rows can be deleted from the table; false otherwisecanMove
- true if rows can be moved up or down in the table; false otherwise
-
InputTablePane
public InputTablePane(InputTablePane.ColSpec[] colspec, Vector<Vector<Object>> rows, boolean canAdd, boolean canDel, boolean canMove) Constructor based on explicitly provided rows.- Parameters:
colspec
- an array (one entry per column in column order) specifying a columnrows
- the table's rows as a Vector of rows, where each row contains a vector whose elements fit the specification provided by the first argument (colspec)canAdd
- true if rows can be added to the table; false otherwisecanDel
- true if rows can be deleted from the table; false otherwisecanMove
- true if rows can be moved up or down in the table; false otherwise
-
InputTablePane
public InputTablePane(InputTablePane.ColSpec[] colspec, int nrows, Vector<Vector<Object>> initialRows, boolean canAdd, boolean canDel, boolean canMove) Constructor with explicitly provided rows, possibly followed by blank rows.- Parameters:
colspec
- an array (one entry per column in column order) specifying a columninitialRows
- the table's initial rows as a Vector of rows, where each row contains a vector whose elements fit the specification provided by the first argument (colspec)nrows
- the number of rowscanAdd
- true if rows can be added to the table; false otherwisecanDel
- true if rows can be deleted from the table; false otherwisecanMove
- true if rows can be moved up or down in the table; false otherwise
-
-
Method Details
-
getCustomRenderer
Get a custom table-cell renderer for a specific row and column. This method should be overridden if a custom table-cell renderer is desired.- Parameters:
tbl
- the internal table used by this object.i
- the row numberj
- the column number- Returns:
- the custom cell editor; null for a default
-
getCustomEditor
Get a custom cell editor for a specific row and column. This method should be overridden if a custom table-cell renderer is desired.- Parameters:
tbl
- the internal table used by this object.i
- the row numberj
- the column number- Returns:
- the custom table-cell renderer; null for a default
-
prohibitEditing
protected boolean prohibitEditing(int row, int col) Prevent editing of specific rows and columns. The default implementation returnsfalse
for any pair of arguments. If the value returned is dependent on a cell's row and column instead of its contents, the behavior of this class may be erratic unless one ensures that those cells cannot be moved (e.g., by usingminimumSelectableRow(int,boolean)
).- Parameters:
row
- the table rowcol
- the table column- Returns:
- true if editing is explicitly prohibited for the given row and column; false otherwise
-
minimumSelectableRow
protected int minimumSelectableRow(int col, boolean allColumnSelection) Limit the range of rows that are selectable for a given column. A table selection may not include a cell for which selection is prohibited. Because the table used in this object's implementation allows only a contiguous selection, rectangular in shape, if any cell within a rectangle is prohibited, the selection cannot be made.The allColumnSelection argument is provided because rows can be inserted, moved or deleted only when a selection includes every column, and one might want to have stricter criteria for that case. The default implementation returns 0 in call cases, so this method will have no effect unless it is overridden.
- Parameters:
col
- the column numberallColumnSelection
- true if all the columns were selected; false otherwise- Returns:
- the first row in the column that may be selected.
-
beforeRowDeletion
protected void beforeRowDeletion(int row) Indicate that a row is about to be deleted- Parameters:
row
- the row number.
-
addTableModelListener
Adds a listener to the list that is notified each time a change to the underlying table's data model occurs.- Parameters:
l
- the TableModelListener
-
removeTableModelListener
Removes a listener from the list that is notified each time a change to the underlying table's data model occurs.- Parameters:
l
- the table model listener to remove
-
getRowCount
public int getRowCount()Get the number of rows in the table.- Returns:
- the number of rows
-
getColumnCount
public int getColumnCount()Get the number of columns in the table.- Returns:
- the number of tables.
-
getValueAt
Get the value of a table cell for this table.- Parameters:
rowIndex
- the row index (starting at 0)columnIndex
- the column index (starting at 0)- Returns:
- the value for the specified row and column
-
setValueAt
Set the valoue of a table cell for this table. As usual, indicies start at 0.- Parameters:
val
- the new valuerow
- the row index into the tablecol
- the column index into the table
-
stopCellEditing
public void stopCellEditing()Stop editing a cell. -
showDialog
public static InputTablePane showDialog(Component parent, String title, InputTablePane.ColSpec[] colspec, int nrows, boolean canAdd, boolean canDel, boolean canMove) Create a new InputTablePane inside a dialog.- Parameters:
parent
- the component on which to center the dialogtitle
- the title of the dialogcolspec
- the column specification for the tablenrows
- the number of rows in the tablecanAdd
- true if rows can be added to the table; false otherwisecanDel
- true if rows can be deleted from the table; false otherwisecanMove
- true if rows can be moved up or down in the table; false otherwise- Returns:
- an input-table pane if successful; null if canceled or closed
-
showDialog
public static InputTablePane showDialog(Component parent, String title, InputTablePane.ColSpec[] colspec, Vector<Vector<Object>> initialRows, boolean canAdd, boolean canDel, boolean canMove) Create a new InputTablePane, initializing some rows, placing the table inside a dialog.- Parameters:
parent
- the component on which to center the dialogtitle
- the title of the dialogcolspec
- the column specification for the tableinitialRows
- the rows to initially add to the table, which determines the initial number of rows in the table.canAdd
- true if rows can be added to the table; false otherwisecanDel
- true if rows can be deleted from the table; false otherwisecanMove
- true if rows can be moved up or down in the table; false otherwise- Returns:
- an input-table pane if successful; null if canceled or closed
-
showDialog
public static InputTablePane showDialog(Component parent, String title, InputTablePane.ColSpec[] colspec, int nrows, Vector<Vector<Object>> initialRows, boolean canAdd, boolean canDel, boolean canMove) Create a new InputTablePane, initializing some rows, placing the table inside a dialog.- Parameters:
parent
- the component on which to center the dialogtitle
- the title of the dialogcolspec
- the column specification for the tableinitialRows
- the rows to initially add to the table, placed as the first rows in the tablenrows
- the number of rows in the tablecanAdd
- true if rows can be added to the table; false otherwisecanDel
- true if rows can be deleted from the table; false otherwisecanMove
- true if rows can be moved up or down in the table; false otherwise- Returns:
- an input-table pane if successful or closed; null if canceled
-
showDialog
Show a dialog containing an InputTablePane
-