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 BooleanColumn header trueNumberConfiguration prototype trueEnumLongest toString()valuetrueColorSquare trueother 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>>calculatorMapprotected ColumnConfigurationconfigurationprotected io.github.jonestimd.swing.table.ValueClassColumnWidthCalculator.WidthCalculatorheaderWidthCalculatorprotected javax.swing.JTabletable
-
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 booleanisFixedWidth(javax.swing.table.TableColumn column)The default implementation returns true if a width calculator has been set for the column.intpreferredWidth(javax.swing.table.TableColumn column)Calculate the preferred width of a column.protected voidsetDefaultCalculators()voidsetWidthCalculator(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.voidsetWidthCalculator(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.voidsetWidthCalculator(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:
isFixedWidthin 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:ColumnWidthCalculatorCalculate the preferred width of a column.- Specified by:
preferredWidthin interfaceColumnWidthCalculator- Parameters:
column- the table column- Returns:
- the preferred width of the column
-
-