Class MetaColumnModel

  • All Implemented Interfaces:
    java.beans.PropertyChangeListener, java.io.Serializable, java.util.EventListener, javax.swing.event.ListSelectionListener, javax.swing.table.TableColumnModel

    public class MetaColumnModel
    extends javax.swing.table.DefaultTableColumnModel
    This ColumnModel provides enhanced functionality over a normal ColumnModel, aimed at making it easy to select which columns in a related TableModel are shown (appear in this ColumnModel) or not shown (don't appear in this ColumnModel). It does this by using an associated ListModel and ListSelectionModel.
    See Also:
    Serialized Form
    • Field Summary

      • Fields inherited from class javax.swing.table.DefaultTableColumnModel

        changeEvent, columnMargin, columnSelectionAllowed, listenerList, selectionModel, tableColumns, totalColumnWidth
    • Constructor Summary

      Constructors 
      Constructor Description
      MetaColumnModel​(javax.swing.table.TableColumnModel baseColumnModel, javax.swing.table.TableModel tableModel)
      Constructs a new MetaColumnModel from a base ColumnModel and a TableModel.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addColumn​(javax.swing.table.TableColumn tcol)
      When a column is added to this TableColumnModel, add it to the listModel and set it visible in the visibleModel
      javax.swing.ListModel getListModel()
      Returns the ListModel representing all the columns in the original TableColumnModel.
      javax.swing.ListSelectionModel getVisibleModel()
      Returns the ListSelectionModel representing which columns in the original TableColumnModel are currently visible (are represented in this ColumnModel) and which are invisible (are not represented in this ColumnModel).
      javax.swing.JMenu makeCheckBoxMenu​(java.lang.String name)
      Returns a menu component which can be used to control the visibility of columns in the model.
      void purgeEmptyColumns()
      Purges this column model of any column which contains nothing but blank entries.
      void removeColumn​(int ipos)
      Sets a column invisible.
      void removeColumn​(javax.swing.table.TableColumn tcol)
      When a column is removed from this TableColumnModel, set it invisible in the visibleModel.
      • Methods inherited from class javax.swing.table.DefaultTableColumnModel

        addColumnModelListener, createSelectionModel, fireColumnAdded, fireColumnMarginChanged, fireColumnMoved, fireColumnRemoved, fireColumnSelectionChanged, getColumn, getColumnCount, getColumnIndex, getColumnIndexAtX, getColumnMargin, getColumnModelListeners, getColumns, getColumnSelectionAllowed, getListeners, getSelectedColumnCount, getSelectedColumns, getSelectionModel, getTotalColumnWidth, moveColumn, propertyChange, recalcWidthCache, removeColumnModelListener, setColumnMargin, setColumnSelectionAllowed, setSelectionModel, valueChanged
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • MetaColumnModel

        public MetaColumnModel​(javax.swing.table.TableColumnModel baseColumnModel,
                               javax.swing.table.TableModel tableModel)
        Constructs a new MetaColumnModel from a base ColumnModel and a TableModel. The base ColumnModel is taken as the initial list of columns that can appear in this ColumnModel, but they can be deleted from and reinstated to this model without affecting the base. Subsequent changes to the base don't change this either.
        Parameters:
        baseColumnModel - the base ColumnModel
        tableModel - the TableModel which supplies the data for the columns this object describes; must refer to the same data as baseColumnModel
    • Method Detail

      • getListModel

        public javax.swing.ListModel getListModel()
        Returns the ListModel representing all the columns in the original TableColumnModel. Every entry in this ListModel will be a TableColumn.
        Returns:
        the list model
      • getVisibleModel

        public javax.swing.ListSelectionModel getVisibleModel()
        Returns the ListSelectionModel representing which columns in the original TableColumnModel are currently visible (are represented in this ColumnModel) and which are invisible (are not represented in this ColumnModel).
        Returns:
        the selection model
      • addColumn

        public void addColumn​(javax.swing.table.TableColumn tcol)
        When a column is added to this TableColumnModel, add it to the listModel and set it visible in the visibleModel
        Specified by:
        addColumn in interface javax.swing.table.TableColumnModel
        Overrides:
        addColumn in class javax.swing.table.DefaultTableColumnModel
      • removeColumn

        public void removeColumn​(javax.swing.table.TableColumn tcol)
        When a column is removed from this TableColumnModel, set it invisible in the visibleModel.
        Specified by:
        removeColumn in interface javax.swing.table.TableColumnModel
        Overrides:
        removeColumn in class javax.swing.table.DefaultTableColumnModel
      • removeColumn

        public void removeColumn​(int ipos)
        Sets a column invisible. The column is identified by its position in the list model, equal to its position in the visible model, equal to its position in the base column model from which this model was initialised.
        Parameters:
        ipos - position of the column to remove
      • purgeEmptyColumns

        public void purgeEmptyColumns()
        Purges this column model of any column which contains nothing but blank entries. Columns purged in this way can be reinstated later by modifying the visibleModel. Such a column will also become visible automatically if at a later date it acquires a non-blank entry.
      • makeCheckBoxMenu

        public javax.swing.JMenu makeCheckBoxMenu​(java.lang.String name)
        Returns a menu component which can be used to control the visibility of columns in the model.
        Parameters:
        name - the name of the menu
        Returns:
        a new JMenu with checkboxes for each column