org.tbee.swing.table
Class JTableHelper

java.lang.Object
  extended by org.tbee.swing.table.JTableHelper

public class JTableHelper
extends java.lang.Object

A few static methods that calculate and set optimal column width based on the preferred sizes of the renderers, editors and headers. TODO: `can we optimize speed by only scanning the visual columns and rows?

Version:
$Revision: 1.24 $

Field Summary
static java.lang.String SOURCECODE_VERSION
          Standard variable for determining version of a class file.
 
Constructor Summary
JTableHelper(javax.swing.JTable table)
           
 
Method Summary
 int getOptimalCellWidth(int col, int row)
          Calculates the optimal width for a cell in the table.
static int getOptimalCellWidth(javax.swing.JTable table, int col, int row)
          Static wrapper for the instance method (backwards compatibility)
 int getOptimalColumnWidth(int col)
          Calculates the optimal width for the column of the given table.
 int getOptimalColumnWidth(int col, int row)
          sets the optimal column width for the given column based on the column and header.
static int getOptimalColumnWidth(javax.swing.JTable table, int col)
          Static wrapper for the instance method (backwards compatibility)
 int getOptimalHeaderWidth(int col)
          Calculates the optimal width for the header of the given table.
static int getOptimalHeaderWidth(javax.swing.JTable table, int col)
          Static wrapper for the instance method (backwards compatibility)
static void scrollToVisible(javax.swing.JTable table, int col, int row)
          Assumes table is contained in a JScrollPane.
 void setOptimalColumnWidth()
          sets the optimal column width for alls column if the given table based on the column and header.
 void setOptimalColumnWidth(int col)
          sets the optimal column width for the given column based on the column and header.
 void setOptimalColumnWidth(int col, int row)
          sets the optimal column width for the given column based on the column and header.
static void setOptimalColumnWidth(javax.swing.JTable table)
          Static wrapper for the instance method (backwards compatibility)
static void setOptimalColumnWidth(javax.swing.JTable table, int col)
          Static wrapper for the instance method (backwards compatibility)
static void setOptimalColumnWidth(javax.swing.JTable table, int col, int row)
          Static wrapper for the instance method (backwards compatibility)
 void setOptimalColumnWidthBasedOnRow(int row)
          sets the optimal column width for the given column based on the column and header.
static void setOptimalColumnWidthBasedOnRow(javax.swing.JTable table, int row)
          Static wrapper for the instance method (backwards compatibility)
 void setOptimalColumnWidthDelayed()
          sets the optimal column width for alls column if the given table based on the column and header.
static void setOptimalColumnWidthDelayed(javax.swing.JTable table)
          Static wrapper for the instance method (backwards compatibility)
 void setOptimalColumnWidthIfLarger()
          sets the optimal column width for alls column if the given table based on the column and header.
 void setOptimalColumnWidthIfLarger(int col)
          sets the optimal column width for the given column based on the column and header.
 void setOptimalColumnWidthIfLarger(int col, int row)
          sets the optimal column width for the given column based on the column and header.
static void setOptimalColumnWidthIfLarger(javax.swing.JTable table)
          Static wrapper for the instance method (backwards compatibility)
static void setOptimalColumnWidthIfLarger(javax.swing.JTable table, int col)
          Static wrapper for the instance method (backwards compatibility)
static void setOptimalColumnWidthIfLarger(javax.swing.JTable table, int col, int row)
          Static wrapper for the instance method (backwards compatibility)
 void setOptimalColumnWidthIfLargerBasedOnRow(int row)
          sets the optimal column width for the given column based on the column and header.
static void setOptimalColumnWidthIfLargerBasedOnRow(javax.swing.JTable table, int row)
          Static wrapper for the instance method (backwards compatibility)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SOURCECODE_VERSION

public static final java.lang.String SOURCECODE_VERSION
Standard variable for determining version of a class file.

See Also:
Constant Field Values
Constructor Detail

JTableHelper

public JTableHelper(javax.swing.JTable table)
Method Detail

getOptimalCellWidth

public static int getOptimalCellWidth(javax.swing.JTable table,
                                      int col,
                                      int row)
Static wrapper for the instance method (backwards compatibility)


getOptimalColumnWidth

public static int getOptimalColumnWidth(javax.swing.JTable table,
                                        int col)
Static wrapper for the instance method (backwards compatibility)


getOptimalHeaderWidth

public static int getOptimalHeaderWidth(javax.swing.JTable table,
                                        int col)
Static wrapper for the instance method (backwards compatibility)


setOptimalColumnWidth

public static void setOptimalColumnWidth(javax.swing.JTable table,
                                         int col)
Static wrapper for the instance method (backwards compatibility)


setOptimalColumnWidth

public static void setOptimalColumnWidth(javax.swing.JTable table,
                                         int col,
                                         int row)
Static wrapper for the instance method (backwards compatibility)


setOptimalColumnWidthBasedOnRow

public static void setOptimalColumnWidthBasedOnRow(javax.swing.JTable table,
                                                   int row)
Static wrapper for the instance method (backwards compatibility)


setOptimalColumnWidthIfLarger

public static void setOptimalColumnWidthIfLarger(javax.swing.JTable table,
                                                 int col)
Static wrapper for the instance method (backwards compatibility)


setOptimalColumnWidthIfLarger

public static void setOptimalColumnWidthIfLarger(javax.swing.JTable table,
                                                 int col,
                                                 int row)
Static wrapper for the instance method (backwards compatibility)


setOptimalColumnWidthIfLargerBasedOnRow

public static void setOptimalColumnWidthIfLargerBasedOnRow(javax.swing.JTable table,
                                                           int row)
Static wrapper for the instance method (backwards compatibility)


setOptimalColumnWidth

public static void setOptimalColumnWidth(javax.swing.JTable table)
Static wrapper for the instance method (backwards compatibility)


setOptimalColumnWidthDelayed

public static void setOptimalColumnWidthDelayed(javax.swing.JTable table)
Static wrapper for the instance method (backwards compatibility)


setOptimalColumnWidthIfLarger

public static void setOptimalColumnWidthIfLarger(javax.swing.JTable table)
Static wrapper for the instance method (backwards compatibility)


getOptimalHeaderWidth

public int getOptimalHeaderWidth(int col)
Calculates the optimal width for the header of the given table. The calculation is based on the preferred width of the header renderer.

Parameters:
col - the column to calculate the widths
Returns:
the width, -1 if error

getOptimalCellWidth

public int getOptimalCellWidth(int col,
                               int row)
Calculates the optimal width for a cell in the table. The calculation is based on the preferred width of the cell editor and renderer.
Taken from the newsgoup de.comp.lang.java with some modifications.
Taken from FOPPS/EnhancedTable - http://fopps.sourceforge.net/

Parameters:
col - the column to calculate the widths
Returns:
the width, -1 if error

getOptimalColumnWidth

public int getOptimalColumnWidth(int col)
Calculates the optimal width for the column of the given table. The calculation is based on the preferred width of the cell editor and renderer.
Taken from the newsgoup de.comp.lang.java with some modifications.
Taken from FOPPS/EnhancedTable - http://fopps.sourceforge.net/

Parameters:
col - the column to calculate the widths
Returns:
the width, -1 if error

getOptimalColumnWidth

public int getOptimalColumnWidth(int col,
                                 int row)
sets the optimal column width for the given column based on the column and header.


setOptimalColumnWidth

public void setOptimalColumnWidth(int col)
sets the optimal column width for the given column based on the column and header.


setOptimalColumnWidth

public void setOptimalColumnWidth(int col,
                                  int row)
sets the optimal column width for the given column based on the column and header.


setOptimalColumnWidthIfLarger

public void setOptimalColumnWidthIfLarger(int col)
sets the optimal column width for the given column based on the column and header.


setOptimalColumnWidthIfLarger

public void setOptimalColumnWidthIfLarger(int col,
                                          int row)
sets the optimal column width for the given column based on the column and header.


setOptimalColumnWidthBasedOnRow

public void setOptimalColumnWidthBasedOnRow(int row)
sets the optimal column width for the given column based on the column and header.


setOptimalColumnWidthIfLargerBasedOnRow

public void setOptimalColumnWidthIfLargerBasedOnRow(int row)
sets the optimal column width for the given column based on the column and header.


setOptimalColumnWidth

public void setOptimalColumnWidth()
sets the optimal column width for alls column if the given table based on the column and header.


setOptimalColumnWidthDelayed

public void setOptimalColumnWidthDelayed()
sets the optimal column width for alls column if the given table based on the column and header.


setOptimalColumnWidthIfLarger

public void setOptimalColumnWidthIfLarger()
sets the optimal column width for alls column if the given table based on the column and header.


scrollToVisible

public static void scrollToVisible(javax.swing.JTable table,
                                   int col,
                                   int row)
Assumes table is contained in a JScrollPane. Scrolls the cell (rowIndex, vColIndex) so that it is visible within the viewport.



Copyright © 2010. All Rights Reserved.