Class GuiUtils.JTables

java.lang.Object
sc.fiji.snt.gui.GuiUtils.JTables
Enclosing class:
GuiUtils

public static class GuiUtils.JTables extends Object
Utility methods for JTable configuration and creation.
  • Method Details

    • scrollPane

      public static JScrollPane scrollPane(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.
      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 wrap
      autoResizeMode - one of the JTable.AUTO_RESIZE_* constants
      showGrid - whether to show grid lines
      showHorizontalLines - whether to show horizontal lines
      Returns:
      a configured JScrollPane containing the table
    • iconHeaderRenderer

      public static TableCellRenderer iconHeaderRenderer(Icon icon, String tooltip)
      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 display
      tooltip - the tooltip for the header cell (may be null)
      Returns:
      a configured TableCellRenderer
    • configureCheckboxColumn

      public static void configureCheckboxColumn(JTable table, int columnIndex, String tooltip)
      Configures a Boolean column to render and edit as a checkbox, with an optional header tooltip.
      Parameters:
      table - the table
      columnIndex - the column index
      tooltip - tooltip for the column header (null to skip)
    • autoSizeColumn

      public static void autoSizeColumn(JTable table, int columnIndex, int padding)
      Auto-sizes the preferred width of the given column to fit its content, with padding.
      Parameters:
      table - the table
      columnIndex - the column index
      padding - extra pixels of padding per side
    • copyToClipboard

      public static void copyToClipboard(JTable table, boolean includeHeaders)
    • assignSearchable

      public static void assignSearchable(JTable table, Function<Object,String> elementConverter, JPopupMenu menu)
    • freezeColumnWidth

      public static void freezeColumnWidth(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.
      Parameters:
      table - the table
      columnIndex - the column index
      padding - 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 model
      line1 - supplier for the primary placeholder text (never null)
      line2 - supplier for the secondary placeholder text (may return null)
      Returns:
      a JTable that paints the placeholder when it has no rows
    • deselectSelectAllMenuItem

      public static JMenuItem deselectSelectAllMenuItem(JTable table, Runnable onChange)
      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 toggled
      onChange - optional callback invoked after the selection mutates (e.g., for recording / scripting); may be null
    • resetColumnOrder

      public static void resetColumnOrder(JTable table)
      Restores the table's column order to match the model order (in case the user dragged columns around).
    • resizeColumns

      public static void resizeColumns(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. If fewer fractions are supplied than the table has columns, the trailing columns are left untouched.
      Parameters:
      table - the table to resize
      widthFractions - fractions of the total column width (e.g. 0.10f, 0.20f, …); ignored when null or 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 on
      onAction - optional callback fired after the operation (e.g., for recording); may be null
      widthFractions - fractions used by the resize step; pass an empty array to only restore column order