Class Table<R>

Type Parameters:
R - The type of object used as row keys.
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, TableModel

public class Table<R> extends JPanel implements TableModel
Wrapper around JTable that allows rows to be identified by key, instead of only by index. It also improves the appearance of the standard JTable by adding column borders and a striped background, both depending on the platform look-and-feel.
See Also:
  • Constructor Details

    • Table

      public Table(List<String> columns)
    • Table

      public Table(String... columns)
  • Method Details

    • getColumnName

      public String getColumnName(int columnIndex)
      Specified by:
      getColumnName in interface TableModel
    • getColumnClass

      public Class<?> getColumnClass(int columnIndex)
      Specified by:
      getColumnClass in interface TableModel
    • getColumnCount

      public int getColumnCount()
      Specified by:
      getColumnCount in interface TableModel
    • setValueAt

      public void setValueAt(Object value, int rowIndex, int columnIndex)
      Specified by:
      setValueAt in interface TableModel
    • getValueAt

      public Object getValueAt(int rowIndex, int columnIndex)
      Specified by:
      getValueAt in interface TableModel
    • isCellEditable

      public boolean isCellEditable(int rowIndex, int columnIndex)
      Specified by:
      isCellEditable in interface TableModel
    • addRow

      public void addRow(R key, List<?> cells)
      Adds a row to this table. The key will be used to identify the row, cells is used to populate the table.
      Throws:
      IllegalArgumentException - if the number of cells does not match the number of columns in this table.
    • addRow

      public void addRow(R key, String firstCell, Object... otherCells)
      Adds a row to this table. The key will be used to identify the row, cells is used to populate the table.
      Throws:
      IllegalArgumentException - if the number of cells does not match the number of columns in this table.
    • removeRow

      public void removeRow(R rowKey)
    • removeRow

      public void removeRow(int rowIndex)
    • removeAllRows

      public void removeAllRows()
    • replaceColumns

      public void replaceColumns(List<String> newColumns)
      Replaces the table's columns with the specified values. Note that this will also remove all rows from the table.
    • getRowCount

      public int getRowCount()
      Specified by:
      getRowCount in interface TableModel
    • getSelectedRowIndex

      @Deprecated public int getSelectedRowIndex()
      Deprecated.
      Use getSelectedRowKey() instead. Using the row index is an unreliable way of identifying towsr, as sorting the table will actually change the row order.
      Returns the index of the row that is currently selected, or -1 when no row is selected.
    • setSelectedRowKey

      public void setSelectedRowKey(R rowKey)
      Changes the selected row to the row associated with the specified key. If the key does not match any of the rows currently displayed in this table, this method does nothing.
    • getSelectedRowKey

      public R getSelectedRowKey()
      Returns the key of the row that is currently selected, or null when no row is selected.
    • setColumnSorter

      public void setColumnSorter(int columnIndex, Comparator<String> columnSorter)
    • setColumnWidth

      public void setColumnWidth(int columnIndex, int width)
    • setTableCellRenderer

      public void setTableCellRenderer(int columnIndex, TableCellRenderer renderer)
    • addTableModelListener

      public void addTableModelListener(TableModelListener tml)
      Specified by:
      addTableModelListener in interface TableModel
    • removeTableModelListener

      public void removeTableModelListener(TableModelListener tml)
      Specified by:
      removeTableModelListener in interface TableModel
    • setRowTooltip

      public void setRowTooltip(R row, String tooltip)
    • getRowTooltip

      public String getRowTooltip(R row)
    • addActionListener

      public void addActionListener(ActionListener al)
    • onSelect

      public Subscribable<R> onSelect()
      Returns a Subscribable that can be used to subscribe to events whenever the selected row changes.
    • onDoubleClick

      public Subscribable<R> onDoubleClick()
      Returns a Subscribable that can be used to subscribe to events whenever the selected row is double-clicked. The event passed to subscribers is the currently selected row key, i.e. the row that was double-clicked.
    • getDoubleClick

      @Deprecated public Subscribable<Table<R>> getDoubleClick()
      Deprecated.
      Use onDoubleClick() instead, which passes the double-clicked row as the event.
      Returns a Subscribable that can be used to subscribe to events whenever the selected row is double-clicked. The event passed to subscribers represents the currently selected row key.