public class OptimalColumnWidthSupport extends MouseAdapter implements PropertyChangeListener
JTable to easily set a table column to an optimal width.
 The optimal width is defined as the maximum length of the currently displayed header and table cell values.
 The setting of optimal colunm widths works best on tables with JTable.AUTO_RESIZE_OFF.
 This class offers two functionalities:
adjustToOptimalColumnWidth(JTable,int) to set any column of any table
       to its optimal width.| Constructor and Description | 
|---|
OptimalColumnWidthSupport(JTable pTable)
Constructor. 
 | 
| Modifier and Type | Method and Description | 
|---|---|
static void | 
adjustToOptimalColumnWidth(JTable pTable)
Adjust the width of all columns of the table. 
 | 
static void | 
adjustToOptimalColumnWidth(JTable pTable,
                          int pViewIndex)
Adjust the width of a column. 
 | 
void | 
dispose()
Disconnect from our table. 
 | 
void | 
mousePressed(MouseEvent pEvent)
We react on the second mouse press to profit from  
JTableHeader.getResizingColumn() which is no longer
 set when the mouse click event occurs. | 
void | 
propertyChange(PropertyChangeEvent pEvent)
We need to notice when the table header is changed so that we can move the mouse listener to the new header. 
 | 
mouseClicked, mouseDragged, mouseEntered, mouseExited, mouseMoved, mouseReleased, mouseWheelMovedpublic OptimalColumnWidthSupport(JTable pTable)
pTable - table to work onpublic void dispose()
public static void adjustToOptimalColumnWidth(JTable pTable)
pTable - table to work onIllegalArgumentException - if table is nullpublic static void adjustToOptimalColumnWidth(JTable pTable, int pViewIndex)
pTable - table to work onpViewIndex - view column indexIllegalArgumentException - if table is nullpublic void propertyChange(PropertyChangeEvent pEvent)
propertyChange in interface PropertyChangeListenerpEvent - table header change eventpublic void mousePressed(MouseEvent pEvent)
JTableHeader.getResizingColumn() which is no longer
 set when the mouse click event occurs.mousePressed in interface MouseListenermousePressed in class MouseAdapterpEvent - mouse eventCopyright © 2017 Jürgen Zeller (privat). All rights reserved.