Package ucar.ui.table

Class HidableTableColumnModel

  • All Implemented Interfaces:
    PropertyChangeListener, Serializable, EventListener, ListSelectionListener, TableModelListener, TableColumnModel

    public class HidableTableColumnModel
    extends DefaultTableColumnModel
    implements TableModelListener
    HidableTableColumnModel extends the DefaultTableColumnModel . It provides a comfortable way to hide/show columns. Columns keep their positions when hidden and shown again.

    In order to work with JTable it cannot add any events to TableColumnModelListener. Therefore hiding a column will result in columnRemoved event and showing it again will notify listeners of a columnAdded, and possibly a columnMoved event. For the same reason the following methods still deal with visible columns only: getColumnCount(), getColumns(), getColumnIndex(), getColumn() There are overloaded versions of these methods that take a parameter onlyVisible which let's you specify whether you want invisible columns taken into account.

    See Also:
    DefaultTableColumnModel, original documentation, Serialized Form
    • Field Detail

      • allTableColumns

        protected Vector<TableColumn> allTableColumns
        Array of TableColumn objects in this model. Holds all column objects, regardless of their visibility.
    • Constructor Detail

      • HidableTableColumnModel

        public HidableTableColumnModel​(TableModel model)
    • Method Detail

      • setColumnVisible

        public void setColumnVisible​(TableColumn column,
                                     boolean visible)
        Sets the visibility of the specified TableColumn. The call is ignored if the TableColumn is not found in this column model or its visibility status did not change.

        Parameters:
        column - the column to show/hide
        visible - its new visibility status
      • isColumnVisible

        public boolean isColumnVisible​(TableColumn aColumn)
        Checks whether the specified column is currently visible.
        Parameters:
        aColumn - column to check
        Returns:
        visibility of specified column (false if there is no such column at all. [It's not visible, right?])
      • moveColumn

        public void moveColumn​(int oldIndex,
                               int newIndex)
        Moves the column from oldIndex to newIndex. Posts columnMoved event. Will not move any columns if oldIndex equals newIndex.
        Specified by:
        moveColumn in interface TableColumnModel
        Overrides:
        moveColumn in class DefaultTableColumnModel
        Parameters:
        oldIndex - index of column to be moved
        newIndex - new index of the column
        Throws:
        IllegalArgumentException - if either oldIndex or newIndex are not in [0, getColumnCount() - 1]
      • getColumnCount

        public int getColumnCount​(boolean onlyVisible)
        Returns the total number of columns in this model.
        Parameters:
        onlyVisible - if set only visible columns will be counted
        Returns:
        the number of columns in the tableColumns array
        See Also:
        getColumns(boolean)
      • getColumns

        public Enumeration<TableColumn> getColumns​(boolean onlyVisible)
        Returns an Enumeration of all the columns in the model.
        Parameters:
        onlyVisible - if set all invisible columns will be missing from the enumeration.
        Returns:
        an Enumeration of the columns in the model
      • getColumn

        public TableColumn getColumn​(int columnIndex,
                                     boolean onlyVisible)
        Returns the TableColumn object for the column at columnIndex.
        Parameters:
        columnIndex - the index of the column desired
        onlyVisible - if set columnIndex is meant to be relative to all visible columns only else it is the index in all columns
        Returns:
        the TableColumn object for the column at columnIndex
      • createColumnsFromModel

        public void createColumnsFromModel​(TableModel newModel)