Package nz.ac.waikato.cms.gui.core
Class JTableHelper
java.lang.Object
nz.ac.waikato.cms.gui.core.JTableHelper
A helper class for JTable, e.g. calculating the optimal colwidth.
- Version:
- $Revision: 14842 $
- Author:
- FracPete (fracpete at waikato dot ac dot nz)
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintcalcColumnWidth(int col) calcs the optimal column width of the given column.static intcalcColumnWidth(JTable table, int col) Calculates the optimal width for the column of the given table.intcalcColumnWidthBounded(int col, int max) calcs the optimal column width of the given column.static intcalcColumnWidthBounded(JTable table, int col, int max) Calculates the optimal width for the column of the given table.intcalcHeaderWidth(int col) calcs the optimal header width of the given column.static intcalcHeaderWidth(JTable table, int col) Calculates the optimal width for the header of the given table.intcalcHeaderWidthBounded(int col, int max) calcs the optimal header width of the given column.static intcalcHeaderWidthBounded(JTable table, int col, int max) Calculates the optimal width for the header of the given table.returns the JTable.voidscrollToVisible(int row, int col) Assumes table is contained in a JScrollPane.static voidscrollToVisible(JTable table, int row, int col) Assumes table is contained in a JScrollPane.voidsets the optimal column width for all columns.voidsetOptimalColumnWidth(int col) sets the optimal column width for the given column.static voidsetOptimalColumnWidth(JTable table) sets the optimal column width for alls column if the given table.static voidsetOptimalColumnWidth(JTable table, int col) sets the optimal column width for the given column.voidsetOptimalColumnWidthBounded(int max) sets the optimal column width for all columns.voidsetOptimalColumnWidthBounded(int col, int max) sets the optimal column width for the given column.static voidsetOptimalColumnWidthBounded(JTable table, int max) sets the optimal column width for alls column if the given table.static voidsetOptimalColumnWidthBounded(JTable table, int col, int max) sets the optimal column width for the given column.voidsets the optimal header width for all columns.voidsetOptimalHeaderWidth(int col) sets the optimal header width for the given column.static voidsetOptimalHeaderWidth(JTable table) sets the optimal header width for alls column if the given table.static voidsetOptimalHeaderWidth(JTable table, int col) sets the optimal header width for the given column.voidsetOptimalHeaderWidthBounded(int col, int max) sets the optimal header width for the given column.static voidsetOptimalHeaderWidthBounded(JTable table, int col, int max) sets the optimal header width for the given column.
-
Field Details
-
LOGGER
for logging. -
MAX_ROWS
public static final int MAX_ROWSthe maximum number of rows to use for calculation.- See Also:
-
m_Table
the table to work with.
-
-
Constructor Details
-
JTableHelper
initializes the object.- Parameters:
table- the table to work on
-
-
Method Details
-
getJTable
returns the JTable.- Returns:
- the table to work on
-
calcColumnWidth
public int calcColumnWidth(int col) calcs the optimal column width of the given column.- Parameters:
col- the column index- Returns:
- the optimal width
-
calcColumnWidthBounded
public int calcColumnWidthBounded(int col, int max) calcs the optimal column width of the given column.- Parameters:
col- the column indexmax- the limit for the column width, -1 for unlimited- Returns:
- the optimal width
-
calcColumnWidth
Calculates the optimal width for the column of the given table. The calculation is based on the preferred width of the header and cell renderer.
Taken from the newsgroup de.comp.lang.java with some modifications.
Taken from FOPPS/EnhancedTable - http://fopps.sourceforge.net/- Parameters:
table- the table to calculate the column widthcol- the column to calculate the widths- Returns:
- the width, -1 if error
-
calcColumnWidthBounded
Calculates the optimal width for the column of the given table. The calculation is based on the preferred width of the header and cell renderer.
Taken from the newsgroup de.comp.lang.java with some modifications.
Taken from FOPPS/EnhancedTable - http://fopps.sourceforge.net/- Parameters:
table- the table to calculate the column widthcol- the column to calculate the widthsmax- the limit for the column width, -1 for unlimited- Returns:
- the width, -1 if error
-
calcHeaderWidth
public int calcHeaderWidth(int col) calcs the optimal header width of the given column.- Parameters:
col- the column index- Returns:
- the optimal width
-
calcHeaderWidthBounded
public int calcHeaderWidthBounded(int col, int max) calcs the optimal header width of the given column.- Parameters:
col- the column indexmax- the limit for the column width, -1 for unlimited- Returns:
- the optimal width
-
calcHeaderWidth
Calculates the optimal width for the header of the given table. The calculation is based on the preferred width of the header renderer.- Parameters:
table- the table to calculate the column widthcol- the column to calculate the widths- Returns:
- the width, -1 if error
-
calcHeaderWidthBounded
Calculates the optimal width for the header of the given table. The calculation is based on the preferred width of the header renderer.- Parameters:
table- the table to calculate the column widthcol- the column to calculate the widthsmax- the limit for the column width, -1 for unlimited- Returns:
- the width, -1 if error
-
setOptimalColumnWidth
public void setOptimalColumnWidth(int col) sets the optimal column width for the given column.- Parameters:
col- the column index
-
setOptimalColumnWidthBounded
public void setOptimalColumnWidthBounded(int col, int max) sets the optimal column width for the given column.- Parameters:
col- the column indexmax- the maximum column width, -1 for unlimited
-
setOptimalColumnWidth
sets the optimal column width for the given column.- Parameters:
table- the table to work oncol- the column index
-
setOptimalColumnWidthBounded
sets the optimal column width for the given column.- Parameters:
table- the table to work oncol- the column indexmax- the maximum column width, -1 for unlimited
-
setOptimalColumnWidth
public void setOptimalColumnWidth()sets the optimal column width for all columns. -
setOptimalColumnWidthBounded
public void setOptimalColumnWidthBounded(int max) sets the optimal column width for all columns. -
setOptimalColumnWidth
sets the optimal column width for alls column if the given table.- Parameters:
table- the table to work on
-
setOptimalColumnWidthBounded
sets the optimal column width for alls column if the given table.- Parameters:
table- the table to work on
-
setOptimalHeaderWidth
public void setOptimalHeaderWidth(int col) sets the optimal header width for the given column.- Parameters:
col- the column index
-
setOptimalHeaderWidthBounded
public void setOptimalHeaderWidthBounded(int col, int max) sets the optimal header width for the given column.- Parameters:
col- the column indexmax- the column width limit, -1 for unlimited
-
setOptimalHeaderWidth
sets the optimal header width for the given column.- Parameters:
table- the table to work oncol- the column index
-
setOptimalHeaderWidthBounded
sets the optimal header width for the given column.- Parameters:
table- the table to work oncol- the column indexmax- the column width limit, -1 for unlimited
-
setOptimalHeaderWidth
public void setOptimalHeaderWidth()sets the optimal header width for all columns. -
setOptimalHeaderWidth
sets the optimal header width for alls column if the given table.- Parameters:
table- the table to work with
-
scrollToVisible
public void scrollToVisible(int row, int col) Assumes table is contained in a JScrollPane. Scrolls the cell (rowIndex, vColIndex) so that it is visible within the viewport.- Parameters:
row- the row indexcol- the column index
-
scrollToVisible
Assumes table is contained in a JScrollPane. Scrolls the cell (rowIndex, vColIndex) so that it is visible within the viewport.- Parameters:
table- the table to work withrow- the row indexcol- the column index
-