Interface GUI


public interface GUI
Factory of host-styled Swing components for plugins, plus static Swing helpers.

The host application (e.g., emuStudio) implements the factory methods and provides the instance via ApplicationApi.getGUI(). Panel layout constraints are MigLayout strings.

  • Method Details

    • relayoutOnShow

      static void relayoutOnShow(Window window)
      Relayouts a window using its actual native insets whenever it becomes showing. This prevents stale decoration spacing from the layout performed before native show. The hierarchy notification runs synchronously, including before a modal dialog's event loop. The listener remains installed when the window is hidden or disposed, so reopening is covered.

      Call once on the Swing event-dispatch thread before the window is first shown.

      Parameters:
      window - window whose layout should be refreshed on show
    • loadIcon

      static ImageIcon loadIcon(String resource, Class<?> resourceClass)
      Loads an icon from a resource. If a matching resource with @2x before the file extension exists (e.g. icon@2x.png for icon.png), it is used for high-resolution rendering.
      Parameters:
      resource - resource path; relative paths are resolved against resourceClass
      resourceClass - class whose classloader is used for resource lookup
      Returns:
      loaded icon, or null if the base resource could not be found
    • loadFontResource

      static Font loadFontResource(String path, Class<?> resourceClass, int size)
      Loads and registers a plain true-type font with kerning enabled.
      Parameters:
      path - resource path; relative paths are resolved against resourceClass
      resourceClass - class whose classloader is used for resource lookup
      size - font size
      Returns:
      loaded font, or a plain Font.MONOSPACED font if the font could not be loaded
    • shortenToFit

      static String shortenToFit(String text, Component component, int width)
      Shortens text to fit the given width when rendered with the component's font.

      The text is cut in the middle, keeping a prefix and suffix around "..."; Unicode characters (grapheme clusters) are kept intact. If even "..." does not fit, only the dots that fit are returned.

      Parameters:
      text - text to shorten
      component - component whose font is used for measuring
      width - available width in pixels; non-positive widths produce an empty string
      Returns:
      text, or its shortened form that fits the width
    • addKeyListenerRecursively

      static void addKeyListenerRecursively(Component component, KeyListener listener)
      Adds a KeyListener to the component and all its descendants, including children added later. Adding the same listener twice has no effect.
      Parameters:
      component - GUI component
      listener - KeyListener object
    • removeKeyListenerRecursively

      static void removeKeyListenerRecursively(Component component, KeyListener listener)
      Removes a KeyListener added by addKeyListenerRecursively(Component, KeyListener) from the component and its descendants.
      Parameters:
      component - GUI component
      listener - KeyListener object
    • toolbarButton

      JButton toolbarButton(Action action)
      Creates a toolbar button from an action. The action provides the icon (Action.SMALL_ICON), tooltip and accessible name (Action.SHORT_DESCRIPTION) and enabled state; the text is hidden.
      Parameters:
      action - button action
      Returns:
      the toolbar button
    • label

      JLabel label(String text)
      Creates a plain label.
      Parameters:
      text - label text
      Returns:
      the label
    • labelBold

      JLabel labelBold(String text)
      Creates a bold label.
      Parameters:
      text - label text
      Returns:
      the bold label
    • button

      JButton button(String text)
      Creates a button; add listeners with AbstractButton.addActionListener(ActionListener).
      Parameters:
      text - button text
      Returns:
      the button
    • buttonMakePrimary

      JButton buttonMakePrimary(JButton button)
      Styles a button as the primary (default) button of a dialog.
      Parameters:
      button - the button
      Returns:
      the same button
    • textField

      JTextField textField(String text, int columns)
      Creates a text field.
      Parameters:
      text - initial text
      columns - number of columns
      Returns:
      the text field
    • textAreaReadOnly

      JTextArea textAreaReadOnly(int rows, int columns)
      Creates a non-editable text area.
      Parameters:
      rows - number of rows
      columns - number of columns
      Returns:
      the text area
    • toolBar

      JToolBar toolBar()
      Creates a horizontal, non-floatable toolbar. Use JToolBar.setOrientation(int) for a vertical one.
      Returns:
      the toolbar
    • splitPane

      JSplitPane splitPane(int orientation, Component first, Component second, double resizeWeight)
      Creates a split pane.
      Parameters:
      orientation - JSplitPane.HORIZONTAL_SPLIT (left to right) or JSplitPane.VERTICAL_SPLIT (top to bottom)
      first - left or top component
      second - right or bottom component
      resizeWeight - how extra space is distributed (0 = all to second, 1 = all to first)
      Returns:
      the split pane
    • scrollPane

      JScrollPane scrollPane(Component view)
      Creates a borderless scroll pane.
      Parameters:
      view - the scrolled component
      Returns:
      the scroll pane
    • panel

      JPanel panel(String layoutConstraints, String colConstraints, String rowConstraints)
      Creates a panel with MigLayout.
      Parameters:
      layoutConstraints - layout constraints
      colConstraints - column constraints
      rowConstraints - row constraints
      Returns:
      the panel
    • section

      JPanel section(String title, String layoutConstraints, String colConstraints, String rowConstraints)
      Creates a panel with MigLayout and a titled border.
      Parameters:
      title - section title
      layoutConstraints - layout constraints
      colConstraints - column constraints
      rowConstraints - row constraints
      Returns:
      the titled panel
    • styleTable

      void styleTable(JTable table)
      Applies the host's table styling. Reapplying the style must not keep increasing row heights.
      Parameters:
      table - the table