Class PFCTable

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, EventListener, Accessible, CellEditorListener, ListSelectionListener, RowSorterListener, TableColumnModelListener, TableModelListener, Scrollable

public class PFCTable extends JTable
PFCTable is a simple wrapper class for JTable, which adds sorting capabilities. By default, sorting is enabled. PFCTable, if used with the Portal Look and Feel, will also enable a table header rollover effect, for column(s) that are sortable. Note: Using the Portal Look and Feel is not a requirement, but is recommended.

Usage: To create a PFCTable which defines all columns to be sortable, use the following methods:

public PFCTable(TableModel model)

public PFCTable(int numRows, int numColumns)

public PFCTable(Vector rowData, Vector columnNames)

public PFCTable(final Object[][] rowData, final Object[] columnNames)


To create a PFCTable which is not sortable, use the following methods, where sortable is set to false

public PFCTable(TableModel model, boolean sortable)

public PFCTable(int numRows, int numColumns, boolean sortable)

public PFCTable(Vector rowData, Vector columnNames, boolean sortable)

public PFCTable(final Object[][] rowData, final Object[] columnNames, boolean sortable)


To create a PFCTable with no data model, use the following method:

public PFCTable()

You can then later add a data model, and make the table sortable by default, by calling the following method:

setModel(TableModel) or make the table not sortable by calling the following method:

setModel(TableModel, boolean sortable) where sortable specified set to false


You can also set all columns to be sortable, by calling the following method:

setSortable(true)


To set an individual column to be sortable, do the following:

setColumnSortable(columnIndex) where columnIndex is the index of the column you wish to make sortable.


To set a column to be sorted alpha-numerically, do the following:

table.setAlphaNumericColumn(columnIndex) where columnIndex is the index of the column you wish to sort alpha-numerically.


There is a test program, called TestTable, which can be used for examples on how to setup various combinations of tables used for sorting.

Author:
Les Thomas
See Also:
  • Constructor Details

    • PFCTable

      public PFCTable()
      Constructs a default PFCTable that is initialized with a default data model, a default column model, and a default selection model. To set a TableModel, call setModel(TableModel model) which will set the table to be sortable by default or setTableModel(TableModel model, boolean sortable), which will set the table to be sortable, based upon specified sortable value.
      See Also:
    • PFCTable

      public PFCTable(TableModel model)
      Convenience method that constructs a default PFCTable that is initialized with a TableModel model, and by default sets all columns to be sortable. To construct a default PFCTable that is not sortable, use PFCTable(TableModel model, boolean sortable) with sortable set to false.
      Parameters:
      model - the data model for the table.
    • PFCTable

      public PFCTable(TableModel model, boolean sortable)
      Convenience method that constructs a default PFCTable that is initialized with a DefaultTableModel model, and by default sets all columns to either be sortable or not, based upon the specified sortable value.
      Parameters:
      model - the data model for the table.
      sortable - true (sortable), false (not sortable).
    • PFCTable

      public PFCTable(int numRows, int numColumns)
      Convenience method that constructs a PFCTable with numRows and numColumns of empty cells using DefaultTableModel. By default, all columns will be set to be sortable. To set the columns to not be sortable, use PFCTable(int numRows, int numColumns, boolean sortable) with sortable set to false. The columns will have names of the form "A", "B", "C", etc.
      Parameters:
      numRows - the number of rows the table holds
      numColumns - the number of columns the table holds
      See Also:
    • PFCTable

      public PFCTable(int numRows, int numColumns, boolean sortable)
      Convenience method that constructs a PFCTable with numRows and numColumns of empty cells using DefaultTableModel. Columns will be set to be either be sortable or not, based upon the sortable value. The columns will have names of the form "A", "B", "C", etc.
      Parameters:
      numRows - the number of rows the table holds
      numColumns - the number of columns the table holds
      sortable - true (sortable), false (not sortable).
      See Also:
    • PFCTable

      public PFCTable(Vector rowData, Vector columnNames)
      Convenience method that constructs a PFCTable to display the values in the Vector of Vectors, rowData , with column names, columnNames. The Vectors contained in rowData should contain the values for that row. In other words, the value of the cell at row 1, column 5 can be obtained with the following code:

      ((Vector)rowData.elementAt(1)).elementAt(5);

      By default, all columns will be set to be sortable. To set the columns to not be sortable, use PFCTable(Vector rowData, Vector columnNames, boolean sortable) with sortable set to false.

      Parameters:
      rowData - the data for the new table
      columnNames - names of each column
    • PFCTable

      public PFCTable(Vector rowData, Vector columnNames, boolean sortable)
      Constructs a PFCTable to display the values in the Vector of Vectors, rowData, with column names, columnNames. The Vectors contained in rowData should contain the values for that row. In other words, the value of the cell at row 1, column 5 can be obtained with the following code:

      ((Vector)rowData.elementAt(1)).elementAt(5);

      Parameters:
      rowData - the data for the new table
      columnNames - names of each column
      sortable - true (sortable), false (not sortable).
    • PFCTable

      public PFCTable(Object[][] rowData, Object[] columnNames)
      Convenience method that constructs a PFCTable to display the values in the two dimensional array, rowData, with column names, columnNames. rowData is an array of rows, so the value of the cell at row 1, column 5 can be obtained with the following code:

       rowData[1][5]; 

      All rows must be of the same length as columnNames.

      By default, all columns will be set to be sortable. To set the columns to not be sortable, use PFCTable(final Object[][] rowData, final Object[] columnNames, boolean sortable) with sortable set to false.

      Parameters:
      rowData - the data for the new table
      columnNames - names of each column
    • PFCTable

      public PFCTable(Object[][] rowData, Object[] columnNames, boolean sortable)
      Convenience method that constructs a PFCTable to display the values in the two dimensional array, rowData, with column names, columnNames. rowData is an array of rows, so the value of the cell at row 1, column 5 can be obtained with the following code:

       rowData[1][5]; 

      All rows must be of the same length as columnNames.

      Columns will be set to be either be sortable or not, based upon the sortable value.

      Parameters:
      rowData - the data for the new table
      columnNames - names of each column
      sortable - true (sortable), false (not sortable)
  • Method Details

    • setModel

      public void setModel(TableModel newModel, boolean sortable)
      Sets the data model for this table to newModel and registers with it for listener notifications from the new data model. Previous listeners will be removed.
      Parameters:
      newModel - the new data source for this table
      sortable - true (sortable), false (not sortable)
    • setModel

      public void setModel(TableModel newModel)
      Sets the data model for this table to newModel and registers with it for listener notifications from the new data model. Previous listeners will be removed. By default, the table will be sortable.
      Overrides:
      setModel in class JTable
      Parameters:
      newModel - the new data source for this table
    • setSortable

      public void setSortable(boolean sortable)
      Sets all the columns in the table to be sortable.
      Parameters:
      sortable - true (sortable), false (not sortable).
    • isTableSortable

      public boolean isTableSortable()
      Returns whether all columns in the table are sortable.
      Returns:
      true (sortable), false otherwise.
    • isColumnSortable

      public boolean isColumnSortable(int columnIndex)
      Returns whether specified column in the table is sortable.
      Parameters:
      columnIndex - index of the column to set
      Returns:
      true (sortable), false if column is not sortable, or columnIndex is invalid.
    • setSortableColumn

      public void setSortableColumn(int columnIndex)
      Sets the specified column, referenced by columnIndex to be sortable.
      Parameters:
      columnIndex - int indicating the column index of the column to be sortable.
      columnIndex - index of the column to set
    • setSortableColumn

      public void setSortableColumn(int columnIndex, boolean sortable)
      Sets the specified column, referenced by columnIndex to be either be sortable or not, based upon the specified sortable value.
      Parameters:
      columnIndex - index of the column to set
      sortable - true (sortable), false (not sortable)
    • setSortableColumns

      public void setSortableColumns(ArrayList columnList)
      Sets the specified columns, contained in the columnList ArrayList to be sortable. Note: ArrayList should contain a list of Integers, representing the indexes for the given columns contained in the table model.
      Parameters:
      columnIndex - ArrayList of Integer's which represent the column index of the columns to be set to sortable.
    • setAlphaNumericColumn

      public void setAlphaNumericColumn(int columnIndex)
      Set the specified column, referenced by columnIndex to be an alpha numeric column. Special sorting algorithm will be used for alpha numeric columns.

      See com.portal.pfc.ui.table.CommonSortRoutines for more details.

      Parameters:
      columnIndex - int indicating the column index of the alpha numeric column.