Package sc.fiji.snt.gui
Class GuiUtils.JTables
java.lang.Object
sc.fiji.snt.gui.GuiUtils.JTables
- Enclosing class:
GuiUtils
Utility methods for
JTable configuration and creation.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classStateful helper that extracts aJScrollPanefrom its current parent into a free-floating, modelessJDialog, and re-attaches it on demand.static classStateful "visiting zoom" helper used by table panels that navigate the canvas on double-click (BookmarkManager, CurationManager, SeedOverlayPanel). -
Method Summary
Modifier and TypeMethodDescriptionstatic voidassignSearchable(JTable table, Function<Object, String> elementConverter, JPopupMenu menu) static voidautoSizeColumn(JTable table, int columnIndex, int padding) Auto-sizes the preferred width of the given column to fit its content, with padding.static voidconfigureCheckboxColumn(JTable table, int columnIndex, String tooltip) Configures a Boolean column to render and edit as a checkbox, with an optional header tooltip.static voidcopyToClipboard(JTable table, boolean includeHeaders) static JMenuItemdeselectSelectAllMenuItem(JTable table, Runnable onChange) Common "Deselect / Select All" toggle menu item.static voidfreezeColumnWidth(JTable table, int columnIndex, int padding) Auto-sizes the given column to fit its content, then freezes it by setting preferred, minimum, and maximum width to the same value.static TableCellRenderericonHeaderRenderer(Icon icon, String tooltip) Creates a header renderer that displays a centered icon instead of text.static JMenuItemresetAndResizeColumnsMenuItem(JTable table, Runnable onAction, float... widthFractions) "Resize/Reset Columns" menu item that restores model column order and then applies width fractions.static voidresetColumnOrder(JTable table) Restores the table's column order to match the model order (in case the user dragged columns around).static voidresizeColumns(JTable table, float... widthFractions) Applies a sequence of preferred column widths to the table, each expressed as a fraction of the current total column width.static JScrollPanescrollPane(JTable table) Wraps a JTable in a JScrollPane with sensible defaults: auto-resize mode set to ALL_COLUMNS, row sorter enabled, and grid lines hidden.static JScrollPanescrollPane(JTable table, int autoResizeMode, boolean showGrid, boolean showHorizontalLines) Wraps a JTable in a JScrollPane, applying common configuration.static JTabletableWithPlaceholder(TableModel model, Supplier<String> line1, Supplier<String> line2) Returns a JTable subclass that draws centered placeholder text when the table model is empty.
-
Method Details
-
scrollPane
Wraps a JTable in a JScrollPane with sensible defaults: auto-resize mode set to ALL_COLUMNS, row sorter enabled, and grid lines hidden.- Parameters:
table- the table to wrap- Returns:
- a configured JScrollPane containing the table
-
scrollPane
public static JScrollPane scrollPane(JTable table, int autoResizeMode, boolean showGrid, boolean showHorizontalLines) Wraps a JTable in a JScrollPane, applying common configuration. Auto-row-sorter is enabled, the table fills the viewport, and intercell spacing is set to zero.- Parameters:
table- the table to wrapautoResizeMode- one of theJTable.AUTO_RESIZE_*constantsshowGrid- whether to show grid linesshowHorizontalLines- whether to show horizontal lines- Returns:
- a configured JScrollPane containing the table
-
iconHeaderRenderer
Creates a header renderer that displays a centered icon instead of text. Inherits the default header foreground, background, font, and border so that the column blends with the rest of the table header.- Parameters:
icon- the icon to displaytooltip- the tooltip for the header cell (may benull)- Returns:
- a configured
TableCellRenderer
-
configureCheckboxColumn
Configures a Boolean column to render and edit as a checkbox, with an optional header tooltip.- Parameters:
table- the tablecolumnIndex- the column indextooltip- tooltip for the column header (null to skip)
-
autoSizeColumn
Auto-sizes the preferred width of the given column to fit its content, with padding.- Parameters:
table- the tablecolumnIndex- the column indexpadding- extra pixels of padding per side
-
copyToClipboard
-
assignSearchable
public static void assignSearchable(JTable table, Function<Object, String> elementConverter, JPopupMenu menu) -
freezeColumnWidth
Auto-sizes the given column to fit its content, then freezes it by setting preferred, minimum, and maximum width to the same value.- Parameters:
table- the tablecolumnIndex- the column indexpadding- extra pixels of padding
-
tableWithPlaceholder
public static JTable tableWithPlaceholder(TableModel model, Supplier<String> line1, Supplier<String> line2) Returns a JTable subclass that draws centered placeholder text when the table model is empty. Two lines are supported: a primary line and an optional secondary line rendered directly below it. Suppliers are used so that placeholder text can change dynamically (e.g., when filters are applied).- Parameters:
model- the table modelline1- supplier for the primary placeholder text (nevernull)line2- supplier for the secondary placeholder text (may returnnull)- Returns:
- a JTable that paints the placeholder when it has no rows
-
deselectSelectAllMenuItem
Common "Deselect / Select All" toggle menu item. Clears the selection if any rows are selected; otherwise selects every row.- Parameters:
table- the table whose selection is toggledonChange- optional callback invoked after the selection mutates (e.g., for recording / scripting); may benull
-
resetColumnOrder
Restores the table's column order to match the model order (in case the user dragged columns around). -
resizeColumns
Applies a sequence of preferred column widths to the table, each expressed as a fraction of the current total column width. If fewer fractions are supplied than the table has columns, the trailing columns are left untouched.- Parameters:
table- the table to resizewidthFractions- fractions of the total column width (e.g.0.10f, 0.20f, …); ignored whennullor empty
-
resetAndResizeColumnsMenuItem
public static JMenuItem resetAndResizeColumnsMenuItem(JTable table, Runnable onAction, float... widthFractions) "Resize/Reset Columns" menu item that restores model column order and then applies width fractions.- Parameters:
table- the table to act ononAction- optional callback fired after the operation (e.g., for recording); may benullwidthFractions- fractions used by the resize step; pass an empty array to only restore column order
-