Package io.github.jonestimd.swing.table
Class ValueClassColumnWidthCalculator
- java.lang.Object
-
- io.github.jonestimd.swing.table.ValueClassColumnWidthCalculator
-
- All Implemented Interfaces:
ColumnWidthCalculator
public class ValueClassColumnWidthCalculator extends java.lang.Object implements ColumnWidthCalculator
Calculates a column's width based on the value returned by
JTable.getColumnClass(int)
. Intended for use with a table model that overridesAbstractTableModel.getColumnClass(int)
because that method always returnsObject.class
. By default, the column cell renderer is used with the value specified below to determine the width.Column Class Renderer Value Fixed Width Boolean
Column header true
Number
Configuration prototype true
Enum
Longest toString()
valuetrue
Color
Square true
other Column header false
- See Also:
BeanListTableModel
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Map<java.lang.Class<?>,java.util.function.ToIntFunction<javax.swing.table.TableColumn>>
calculatorMap
protected ColumnConfiguration
configuration
protected io.github.jonestimd.swing.table.ValueClassColumnWidthCalculator.WidthCalculator
headerWidthCalculator
protected javax.swing.JTable
table
-
Constructor Summary
Constructors Constructor Description ValueClassColumnWidthCalculator(javax.swing.JTable table, ColumnConfiguration configuration)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
isFixedWidth(javax.swing.table.TableColumn column)
The default implementation returns true if a width calculator has been set for the column.int
preferredWidth(javax.swing.table.TableColumn column)
Calculate the preferred width of a column.protected void
setDefaultCalculators()
void
setWidthCalculator(java.lang.Class<?> valueType, java.util.function.Function<javax.swing.table.TableColumn,?> getPrototype)
Use the header width for a prototype value as the column width.void
setWidthCalculator(java.lang.Class<?> valueType, java.util.function.Function<javax.swing.table.TableColumn,?> getPrototype, java.util.function.ToIntFunction<java.awt.Component> getWidth)
Calculate the column width using the header renderer for a prototype value.void
setWidthCalculator(java.lang.Class<?> valueType, java.util.function.ToIntFunction<javax.swing.table.TableColumn> calculator)
Set the calculator for a column value type.
-
-
-
Field Detail
-
headerWidthCalculator
protected final io.github.jonestimd.swing.table.ValueClassColumnWidthCalculator.WidthCalculator headerWidthCalculator
-
calculatorMap
protected final java.util.Map<java.lang.Class<?>,java.util.function.ToIntFunction<javax.swing.table.TableColumn>> calculatorMap
-
table
protected final javax.swing.JTable table
-
configuration
protected final ColumnConfiguration configuration
-
-
Constructor Detail
-
ValueClassColumnWidthCalculator
public ValueClassColumnWidthCalculator(javax.swing.JTable table, ColumnConfiguration configuration)
-
-
Method Detail
-
setDefaultCalculators
protected void setDefaultCalculators()
-
setWidthCalculator
public void setWidthCalculator(java.lang.Class<?> valueType, java.util.function.ToIntFunction<javax.swing.table.TableColumn> calculator)
Set the calculator for a column value type.
-
setWidthCalculator
public void setWidthCalculator(java.lang.Class<?> valueType, java.util.function.Function<javax.swing.table.TableColumn,?> getPrototype)
Use the header width for a prototype value as the column width.- Parameters:
getPrototype
- a function that returns the prototype value for a column
-
setWidthCalculator
public void setWidthCalculator(java.lang.Class<?> valueType, java.util.function.Function<javax.swing.table.TableColumn,?> getPrototype, java.util.function.ToIntFunction<java.awt.Component> getWidth)
Calculate the column width using the header renderer for a prototype value.- Parameters:
getPrototype
- a function that returns the prototype value for a columngetWidth
- a function that returns the width for the column given the header renderer
-
isFixedWidth
public boolean isFixedWidth(javax.swing.table.TableColumn column)
The default implementation returns true if a width calculator has been set for the column.- Specified by:
isFixedWidth
in interfaceColumnWidthCalculator
- Returns:
- true if the column's min, max and preferred widths should all be initialized to the value returned by
ColumnWidthCalculator.preferredWidth(TableColumn)
-
preferredWidth
public int preferredWidth(javax.swing.table.TableColumn column)
Description copied from interface:ColumnWidthCalculator
Calculate the preferred width of a column.- Specified by:
preferredWidth
in interfaceColumnWidthCalculator
- Parameters:
column
- the table column- Returns:
- the preferred width of the column
-
-