Package adams.gui.core
Class JTableHelper
- java.lang.Object
-
- adams.gui.core.JTableHelper
-
public class JTableHelper extends Object
A helper class for JTable, e.g. calculating the optimal colwidth.- Author:
- FracPete (fracpete at waikato dot ac dot nz)
- See Also:
JTableHelper
-
-
Field Summary
Fields Modifier and Type Field Description protected static Logger
LOGGER
for logging.protected JTable
m_Table
the table to work with.static int
MAX_CHARS
the maximum number of characters before skipping optimal column width.static int
MAX_ROWS
the maximum number of rows to use for calculation.
-
Constructor Summary
Constructors Constructor Description JTableHelper(JTable table)
initializes the object.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
calcColumnWidth(int col)
calcs the optimal column width of the given column.static int
calcColumnWidth(JTable table, int col)
Calculates the optimal width for the column of the given table.int
calcColumnWidthBounded(int col, int max)
calcs the optimal column width of the given column.static int
calcColumnWidthBounded(JTable table, int col, int max)
Calculates the optimal width for the column of the given table.int
calcHeaderWidth(int col)
calcs the optimal header width of the given column.static int
calcHeaderWidth(JTable table, int col)
Calculates the optimal width for the header of the given table.int
calcHeaderWidthBounded(int col, int max)
calcs the optimal header width of the given column.static int
calcHeaderWidthBounded(JTable table, int col, int max)
Calculates the optimal width for the header of the given table.JTable
getJTable()
returns the JTable.void
scrollToVisible(int row, int col)
Assumes table is contained in a JScrollPane.static void
scrollToVisible(JTable table, int row, int col)
Assumes table is contained in a JScrollPane.void
setOptimalColumnWidth()
sets the optimal column width for all columns.void
setOptimalColumnWidth(int col)
sets the optimal column width for the given column.static void
setOptimalColumnWidth(JTable table)
sets the optimal column width for alls column if the given table.static void
setOptimalColumnWidth(JTable table, int col)
sets the optimal column width for the given column.void
setOptimalColumnWidthBounded(int max)
sets the optimal column width for all columns.void
setOptimalColumnWidthBounded(int col, int max)
sets the optimal column width for the given column.static void
setOptimalColumnWidthBounded(JTable table, int max)
sets the optimal column width for alls column if the given table.static void
setOptimalColumnWidthBounded(JTable table, int col, int max)
sets the optimal column width for the given column.void
setOptimalColumnWidths(int[] cols)
sets the optimal column width for the given columns.static void
setOptimalColumnWidths(JTable table, int[] cols)
sets the optimal column width for the given columns.void
setOptimalColumnWidthsBounded(int[] cols, int max)
sets the optimal column width for the given columns.static void
setOptimalColumnWidthsBounded(JTable table, int[] cols, int max)
sets the optimal column width for the given columns.void
setOptimalHeaderWidth()
sets the optimal header width for all columns.void
setOptimalHeaderWidth(int col)
sets the optimal header width for the given column.static void
setOptimalHeaderWidth(JTable table)
sets the optimal header width for alls column if the given table.static void
setOptimalHeaderWidth(JTable table, int col)
sets the optimal header width for the given column.void
setOptimalHeaderWidthBounded(int col, int max)
sets the optimal header width for the given column.static void
setOptimalHeaderWidthBounded(JTable table, int col, int max)
sets the optimal header width for the given column.static SpreadSheet
toSpreadSheet(JTable table)
Turns a table into a spreadsheet.static SpreadSheet
toSpreadSheet(TableModel model)
Turns a table model into a spreadsheet.
-
-
-
Field Detail
-
LOGGER
protected static Logger LOGGER
for logging.
-
MAX_ROWS
public static final int MAX_ROWS
the maximum number of rows to use for calculation.- See Also:
- Constant Field Values
-
MAX_CHARS
public static final int MAX_CHARS
the maximum number of characters before skipping optimal column width.- See Also:
- Constant Field Values
-
m_Table
protected JTable m_Table
the table to work with.
-
-
Constructor Detail
-
JTableHelper
public JTableHelper(JTable table)
initializes the object.- Parameters:
table
- the table to work on
-
-
Method Detail
-
getJTable
public JTable 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
public static int calcColumnWidth(JTable table, int col)
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
public static int calcColumnWidthBounded(JTable table, int col, int max)
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
public static int calcHeaderWidth(JTable table, 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:
table
- the table to calculate the column widthcol
- the column to calculate the widths- Returns:
- the width, -1 if error
-
calcHeaderWidthBounded
public static int calcHeaderWidthBounded(JTable table, int col, int max)
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
public static void setOptimalColumnWidth(JTable table, int col)
sets the optimal column width for the given column.- Parameters:
table
- the table to work oncol
- the column index
-
setOptimalColumnWidthBounded
public static void setOptimalColumnWidthBounded(JTable table, int col, int max)
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
-
setOptimalColumnWidths
public void setOptimalColumnWidths(int[] cols)
sets the optimal column width for the given columns.- Parameters:
cols
- the column indices
-
setOptimalColumnWidths
public static void setOptimalColumnWidths(JTable table, int[] cols)
sets the optimal column width for the given columns.- Parameters:
table
- the table to work oncols
- the column indices
-
setOptimalColumnWidthsBounded
public void setOptimalColumnWidthsBounded(int[] cols, int max)
sets the optimal column width for the given columns.- Parameters:
cols
- the column indicesmax
- the maximum column width, -1 for unlimited
-
setOptimalColumnWidthsBounded
public static void setOptimalColumnWidthsBounded(JTable table, int[] cols, int max)
sets the optimal column width for the given columns.- Parameters:
table
- the table to work oncols
- the column indicesmax
- 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
public static void setOptimalColumnWidth(JTable table)
sets the optimal column width for alls column if the given table.- Parameters:
table
- the table to work on
-
setOptimalColumnWidthBounded
public static void setOptimalColumnWidthBounded(JTable table, int max)
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
public static void setOptimalHeaderWidth(JTable table, int col)
sets the optimal header width for the given column.- Parameters:
table
- the table to work oncol
- the column index
-
setOptimalHeaderWidthBounded
public static void setOptimalHeaderWidthBounded(JTable table, int col, int max)
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
public static void setOptimalHeaderWidth(JTable table)
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
public static void scrollToVisible(JTable table, 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:
table
- the table to work withrow
- the row indexcol
- the column index
-
toSpreadSheet
public static SpreadSheet toSpreadSheet(JTable table)
Turns a table into a spreadsheet.- Parameters:
table
- the table to convert- Returns:
- the generated spreadsheet
-
toSpreadSheet
public static SpreadSheet toSpreadSheet(TableModel model)
Turns a table model into a spreadsheet.- Parameters:
model
- the table model to convert- Returns:
- the generated spreadsheet
-
-