Class GuiUtils.JTables.DetachableTable

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

public static class GuiUtils.JTables.DetachableTable extends Object
Stateful helper that extracts a JScrollPane from its current parent into a free-floating, modeless JDialog, and re-attaches it on demand. Designed for "Detach Table / Dock Table" UI patterns.

Because Swing layouts (notably GridBagLayout) don't preserve per-component constraints across remove/add, the redocker callback supplied by the caller is responsible for re-adding the scroll pane to its original parent with the appropriate constraints.

Closing the detached dialog (window-close button) triggers a dock.

See Also:
  • Constructor Details

    • DetachableTable

      public DetachableTable(JScrollPane scroll, String detachedTitle, Runnable redocker)
      Parameters:
      scroll - the scroll pane that wraps the JTable
      detachedTitle - title for the detached JDialog
      redocker - caller-supplied logic that re-adds scroll to its original parent with the correct layout constraints; called once per dock (including when the user closes the detached window)
    • DetachableTable

      public DetachableTable(JScrollPane scroll, String detachedTitle, Runnable redocker, Dimension detachedSize)
      Parameters:
      detachedSize - initial size of the detached JDialog (e.g. new Dimension(500, 240))
  • Method Details

    • isDetached

      public boolean isDetached()
      Returns:
      true when the table is currently floating in its own dialog.
    • detach

      public void detach()
      Detaches into a floating dialog. No-op if already detached.
    • dock

      public void dock()
      Re-attaches via the caller's redocker. No-op if already docked.
    • toggle

      public void toggle()
      Convenience: dock() when detached, detach() otherwise.
    • installMenuItem

      public JMenuItem installMenuItem(JPopupMenu menu)
      Adds a "Detach Table" / "Dock Table" toggle item to the given popup menu. The label is kept in sync via a PopupMenuListener, so closing the detached dialog with its window-close button is reflected next time the popup opens.
      Parameters:
      menu - the popup to append the item to
      Returns:
      the installed JMenuItem (already added to menu)