FreeHEP API
Version current

org.freehep.swing.table
Class TableColumnSelector

java.lang.Object
  extended byorg.freehep.swing.table.TableColumnSelector

public class TableColumnSelector
extends Object

Allows the user to select which columns are visible in a table.

Example of usage:

    TableModel model = ...
    TableColumnSelector selector = new TableColumnSelector(model);
    JTable table = new JTable(selector.getFilteredTableModel());
    table.addMouseListener(new PopupListener(selector.createPopupMenu()));
 

Author:
Tony Johnson
Source Code:
TableColumnSelector.java

Constructor Summary
TableColumnSelector(TableModel model)
          Create a TableColumnSelector.
 
Method Summary
 JPopupMenu createPopupMenu()
          Creates a JPopupMenu filled with appropriate JCheckBoxMenuItems.
protected  void fireTableChanged(TableModelEvent event)
          Notifies all listeners of a change to the filtered TableModel.
 TableModel getFilteredTableModel()
          Get the resulting table model.
 boolean isHideColumn(int columnIndex)
          Test if a column is hidden.
 void populateMenu(JComponent menu)
          Can be used to fill a JMenu or JPopupMenu with appropriate JCheckBoxMenuItems.
 void setHideColumn(int columnIndex, boolean hide)
          Show or Hide the specied column.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TableColumnSelector

public TableColumnSelector(TableModel model)
Create a TableColumnSelector.

Parameters:
model - The source table model.
Method Detail

populateMenu

public void populateMenu(JComponent menu)
Can be used to fill a JMenu or JPopupMenu with appropriate JCheckBoxMenuItems.

Parameters:
menu - The JMenu or JPopupMenu to populate.

createPopupMenu

public JPopupMenu createPopupMenu()
Creates a JPopupMenu filled with appropriate JCheckBoxMenuItems. Can be used as the popup menu for the JTable.

Returns:
The created menu.

setHideColumn

public void setHideColumn(int columnIndex,
                          boolean hide)
Show or Hide the specied column.

Parameters:
columnIndex - The columnIndex in the source TableModel
hide - if true hides this column

fireTableChanged

protected void fireTableChanged(TableModelEvent event)
Notifies all listeners of a change to the filtered TableModel.

Parameters:
event - The event to be sent to the listeners.

isHideColumn

public boolean isHideColumn(int columnIndex)
Test if a column is hidden.

Parameters:
columnIndex - The columnIndex in the source TableModel.
Returns:
true if this column is hidden

getFilteredTableModel

public TableModel getFilteredTableModel()
Get the resulting table model. This is the table model that should actually be installed.

Returns:
The filtered table mode.

FreeHEP API
Version current

Copyright © 2000-2004 FreeHEP, All Rights Reserved.