Class InputTablePane

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class InputTablePane extends JPanel
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:
  • Field Details

  • 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 column
      nrows - the number of rows
      canAdd - true if rows can be added to the table; false otherwise
      canDel - true if rows can be deleted from the table; false otherwise
      canMove - 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 column
      rows - 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 otherwise
      canDel - true if rows can be deleted from the table; false otherwise
      canMove - 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 column
      initialRows - 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 rows
      canAdd - true if rows can be added to the table; false otherwise
      canDel - true if rows can be deleted from the table; false otherwise
      canMove - true if rows can be moved up or down in the table; false otherwise
  • Method Details

    • getCustomRenderer

      protected TableCellRenderer getCustomRenderer(JTable tbl, int i, int j)
      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 number
      j - the column number
      Returns:
      the custom cell editor; null for a default
    • getCustomEditor

      protected TableCellEditor getCustomEditor(JTable tbl, int i, int j)
      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 number
      j - 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 returns false 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 using minimumSelectableRow(int,boolean)).
      Parameters:
      row - the table row
      col - 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 number
      allColumnSelection - 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

      public void addTableModelListener(TableModelListener l)
      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

      public void removeTableModelListener(TableModelListener l)
      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

      public Object getValueAt(int rowIndex, int columnIndex)
      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

      public void setValueAt(Object val, int row, int col)
      Set the valoue of a table cell for this table. As usual, indicies start at 0.
      Parameters:
      val - the new value
      row - the row index into the table
      col - 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 dialog
      title - the title of the dialog
      colspec - the column specification for the table
      nrows - the number of rows in the table
      canAdd - true if rows can be added to the table; false otherwise
      canDel - true if rows can be deleted from the table; false otherwise
      canMove - 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 dialog
      title - the title of the dialog
      colspec - the column specification for the table
      initialRows - 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 otherwise
      canDel - true if rows can be deleted from the table; false otherwise
      canMove - 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 dialog
      title - the title of the dialog
      colspec - the column specification for the table
      initialRows - the rows to initially add to the table, placed as the first rows in the table
      nrows - the number of rows in the table
      canAdd - true if rows can be added to the table; false otherwise
      canDel - true if rows can be deleted from the table; false otherwise
      canMove - 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

      public static int showDialog(Component parent, String title, InputTablePane ipane)
      Show a dialog containing an InputTablePane
      Parameters:
      parent - the component on which to center the dialog
      title - the title of the dialog
      ipane - the InputTablePane to display
      Returns:
      OK if the input is accepted; CANCEL if the input is cancelled