Class MultilineJTable

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

public class MultilineJTable extends JTable
JTable which can display multiple-line elements. This class behaves like a JTable except that any of its cells which contain String objects with newline characters ('\n'), or String[] arrays are displayed on multiple table rows.

The implementation may make some demands in consequence of this; it may require that the data in the TableModel does not change while this table is active, and it may need to read the whole TableModel prior to startup. If these demands exist, they may be relaxed by improved implemenatation in the future.

Because the number of rows is modified, it is unwise to make any TableCellRenderers (or TableCellEditors?) associated with this table sensitive to the index of the row with which they are dealing.

Author:
Mark Taylor (Starlink)
See Also:
  • Constructor Details

    • MultilineJTable

      public MultilineJTable(TableModel baseModel)
      Constructs a new table given a base TableModel. The model of this JTable is not actually the base model supplied, a new model derived from that one (potentially with more rows) is used.
      Parameters:
      baseModel - a TableModel describing the data this table will display
    • MultilineJTable

      public MultilineJTable()
      Constructs a MultilineJTable without any data. Its TableModel is initialised to null.
  • Method Details

    • setModel

      public void setModel(TableModel baseModel)
      Sets the model which this table should display. The model of this JTable is not actually the base model supplied, a new model derived from that one (potentially with more rows) is used.
      Overrides:
      setModel in class JTable
      Parameters:
      baseModel - a TableModel describing the data this table will display
    • getModel

      public TableModel getModel()
      Returns the model which this table is using for data display. Note that this will not be the same object as that specified in the constructor or setModel(javax.swing.table.TableModel) method, it will be some model derived from that one (potentially with more rows).
      Overrides:
      getModel in class JTable
      Returns:
      a TableModel used for display
    • prepareRenderer

      public Component prepareRenderer(TableCellRenderer rend, int row, int col)
      Overrides:
      prepareRenderer in class JTable
    • setGridColor

      public void setGridColor(Color gridColor)
      Overrides:
      setGridColor in class JTable