Package org.openstreetmap.josm.gui.util
Class TableHelper
- java.lang.Object
-
- org.openstreetmap.josm.gui.util.TableHelper
-
public final class TableHelper extends Object
The class that provide common JTable customization methods- Since:
- 5785
-
-
Constructor Summary
Constructors Modifier Constructor Description private
TableHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
adaptTo(IEnabledStateUpdating listener, ListSelectionModel listSelectionModel)
Wireslistener
tolistSelectionModel
in such a way, thatlistener
receives aIEnabledStateUpdating.updateEnabledState()
on everyListSelectionEvent
.static void
adaptTo(IEnabledStateUpdating listener, AbstractTableModel listModel)
Wireslistener
tolistModel
in such a way, thatlistener
receives aIEnabledStateUpdating.updateEnabledState()
on everyListDataEvent
.static void
adjustColumnWidth(JTable tbl, int col, boolean resizable)
adjust the preferred width of column col to the maximum preferred width of the cells (including header)static void
adjustColumnWidth(JTable tbl, int col, int maxColumnWidth)
adjust the preferred width of column col to the maximum preferred width of the cells (including header) requires JTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);static void
computeColumnsWidth(JTable tbl)
adjust the table's columns to fit their content best requires JTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);(package private) static int
getColumnHeaderWidth(JTable tbl, int col)
(package private) static int
getMaxWidth(JTable tbl, int col)
static int[]
getSelectedIndices(ListSelectionModel selectionModel)
Returns an array of all of the selected indices in the selection model, in increasing order.static IntStream
selectedIndices(ListSelectionModel selectionModel)
Returns a stream of all of the selected indices in the selection model, in increasing order.static void
setFont(JTable table, Class<? extends Component> parent)
Sets the table font size based on the font scaling from the preferencesstatic void
setSelectedIndices(ListSelectionModel selectionModel, IntStream indices)
Selects the given indices in the selection model
-
-
-
Constructor Detail
-
TableHelper
private TableHelper()
-
-
Method Detail
-
adaptTo
public static void adaptTo(IEnabledStateUpdating listener, ListSelectionModel listSelectionModel)
Wireslistener
tolistSelectionModel
in such a way, thatlistener
receives aIEnabledStateUpdating.updateEnabledState()
on everyListSelectionEvent
.- Parameters:
listener
- the listenerlistSelectionModel
- the source emittingListSelectionEvent
s- Since:
- 15226
-
adaptTo
public static void adaptTo(IEnabledStateUpdating listener, AbstractTableModel listModel)
Wireslistener
tolistModel
in such a way, thatlistener
receives aIEnabledStateUpdating.updateEnabledState()
on everyListDataEvent
.- Parameters:
listener
- the listenerlistModel
- the source emittingListDataEvent
s- Since:
- 15226
-
getColumnHeaderWidth
static int getColumnHeaderWidth(JTable tbl, int col)
-
getMaxWidth
static int getMaxWidth(JTable tbl, int col)
-
adjustColumnWidth
public static void adjustColumnWidth(JTable tbl, int col, boolean resizable)
adjust the preferred width of column col to the maximum preferred width of the cells (including header)- Parameters:
tbl
- tablecol
- column indexresizable
- if true, resizing is allowed- Since:
- 15176
-
adjustColumnWidth
public static void adjustColumnWidth(JTable tbl, int col, int maxColumnWidth)
adjust the preferred width of column col to the maximum preferred width of the cells (including header) requires JTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);- Parameters:
tbl
- tablecol
- column indexmaxColumnWidth
- maximum column width
-
computeColumnsWidth
public static void computeColumnsWidth(JTable tbl)
adjust the table's columns to fit their content best requires JTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);- Parameters:
tbl
- table- Since:
- 14476
-
getSelectedIndices
public static int[] getSelectedIndices(ListSelectionModel selectionModel)
Returns an array of all of the selected indices in the selection model, in increasing order. Unfortunately this method is not available in OpenJDK before version 11, see https://bugs.openjdk.java.net/browse/JDK-8199395 To be removed when we switch to Java 11 or later.- Parameters:
selectionModel
- list selection model.- Returns:
- all of the selected indices, in increasing order, or an empty array if nothing is selected
- Since:
- 15226
- See Also:
selectedIndices(ListSelectionModel)
-
selectedIndices
public static IntStream selectedIndices(ListSelectionModel selectionModel)
Returns a stream of all of the selected indices in the selection model, in increasing order.- Parameters:
selectionModel
- list selection model.- Returns:
- all of the selected indices, in increasing order, or an empty stream if nothing is selected
- Since:
- 17773
-
setSelectedIndices
public static void setSelectedIndices(ListSelectionModel selectionModel, IntStream indices)
Selects the given indices in the selection model- Parameters:
selectionModel
- list selection model.indices
- the indices to select- Since:
- 16601
- See Also:
ListSelectionModel.addSelectionInterval(int, int)
-
setFont
public static void setFont(JTable table, Class<? extends Component> parent)
Sets the table font size based on the font scaling from the preferences- Parameters:
table
- the tableparent
- the parent component used for determining the preference key- See Also:
JComponent.setFont(Font)
,JTable.setRowHeight(int)
-
-