com.sciapp.table
Class TableAssistant

java.lang.Object
  extended by com.sciapp.table.TableAssistant

public class TableAssistant
extends Object

TableAssistant is a class that provides additional functions to a JTable. More specifically:

1) It automatically resizes the column of a table to the greatest preferred width of all cells under that column, when the column is double-clicked on its border.

2) Provides a popup through which the columns of the table can be dynamically added/removed. The popup is shown upon right-clicking on the table header.


Constructor Summary
TableAssistant(JTable table)
          Constructs a TableAssistant having table as the JTable on which this object acts.
 
Method Summary
protected  JPopupMenu createPopup()
           
 void deselect(int modelIndex)
          Unchecks the column with model index modelIndex from the column popup.
 JPopupMenu getColumnPopup()
          Returns the popup menu displayed.
 boolean getShowPopup()
          Returns true if the column popup is to be shown.
 void register(TableColumnModel tcm)
          The component registers itself to the listener list of tcm.
 void resizeColumnToContents(int column)
          Resizes the given column to its contents.
 void select(int modelIndex)
          Checks the column with model index modelIndex from the column popup.
 void setHeader(JTableHeader newTableHeader)
          Associates newTableHeader with this instance of TableAssistant.
 void setShowPopup(boolean showPopup)
          Sets a flag that is true if the column popup is to be shown.
 void unregister(TableColumnModel tcm)
          The component unregisters itself from the listener list of tcm.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TableAssistant

public TableAssistant(JTable table)
Constructs a TableAssistant having table as the JTable on which this object acts.

Parameters:
table - the table
Method Detail

createPopup

protected JPopupMenu createPopup()

deselect

public void deselect(int modelIndex)
Unchecks the column with model index modelIndex from the column popup.

Parameters:
modelIndex - the model index of the table's column

getColumnPopup

public JPopupMenu getColumnPopup()
Returns the popup menu displayed.

Returns:
the popup menu.

getShowPopup

public boolean getShowPopup()
Returns true if the column popup is to be shown.

Returns:
the show popup flag

register

public void register(TableColumnModel tcm)
The component registers itself to the listener list of tcm.

Parameters:
tcm - the TableColumnModel

resizeColumnToContents

public void resizeColumnToContents(int column)
Resizes the given column to its contents. This method is also called when double-clicking with the mouse on the column's border.

Parameters:
column - the table column to resize

select

public void select(int modelIndex)
Checks the column with model index modelIndex from the column popup.

Parameters:
modelIndex - the model index of the table's column

setHeader

public void setHeader(JTableHeader newTableHeader)
Associates newTableHeader with this instance of TableAssistant.

Parameters:
newTableHeader - the JTableHeader to associate with this TableAssistant.

setShowPopup

public void setShowPopup(boolean showPopup)
Sets a flag that is true if the column popup is to be shown.

Parameters:
showPopup - the show popup value to set

unregister

public void unregister(TableColumnModel tcm)
The component unregisters itself from the listener list of tcm.

Parameters:
tcm - the TableColumnModel