Class Utilities

java.lang.Object
is.codion.swing.common.ui.Utilities

public final class Utilities extends Object
A utility class for UI related things.
  • Method Details

    • updateUI

      public static void updateUI(@Nullable JComponent... components)
      Calls JComponent.updateUI() for the given components, ignores null components.
      Parameters:
      components - the components to update the UI for
    • updateUI

      public static void updateUI(Collection<? extends JComponent> components)
      Calls JComponent.updateUI() for the given components, ignores null components.
      Parameters:
      components - the components to update the UI for
    • updateComponentTreeUI

      public static void updateComponentTreeUI(@Nullable JComponent... components)
      Calls SwingUtilities.updateComponentTreeUI(Component) for the given components, ignores null components.
      Parameters:
      components - the components to update the UI for
    • updateComponentTreeUI

      public static void updateComponentTreeUI(Collection<? extends JComponent> components)
      Calls SwingUtilities.updateComponentTreeUI(Component) for the given components, ignores null components.
      Parameters:
      components - the components to update the UI for
    • updateComponentTreeForAllWindows

      public static void updateComponentTreeForAllWindows()
      See Also:
    • enabled

      public static void enabled(ObservableState enabledState, @Nullable Action... actions)
      Links the given actions to the given ObservableState, so that the actions are enabled only when the observed state is active
      Parameters:
      enabledState - the ObservableState with which to link the actions
      actions - the actions
    • enabled

      public static void enabled(ObservableState enabledState, @Nullable JComponent... components)
      Links the given components to the given ObservableState, so that each component is enabled only when the observed state is active
      Parameters:
      enabledState - the ObservableState with which to link the components
      components - the components
    • observer

      public static <T> Observer<T> observer(JComponent component, String property)
      Returns a Observer notified each time the value of the given property changes in the given component.
      Type Parameters:
      T - the property data type
      Parameters:
      component - the component
      property - the property to listen to changes for
      Returns:
      a Observer notified each time the value of the given property changes
    • link

      public static void link(BoundedRangeModel main, BoundedRangeModel linked)
      Links the given BoundedRangeModels so that changes in main are reflected in linked
      Parameters:
      main - the main model
      linked - the model to link with main
    • expandAll

      public static void expandAll(JTree tree, TreePath parent)
      Expands all the paths from a parent in the given tree
      Parameters:
      tree - the tree
      parent - the parent from which to exapand
    • collapseAll

      public static void collapseAll(JTree tree, TreePath parent)
      Collapses all the paths from a parent in the given tree
      Parameters:
      tree - the tree
      parent - the parent from which to collapse
    • loadIcon

      public static ImageIcon loadIcon(Class<?> resourceClass, String resourceName)
      Loads an icon as a resource
      Parameters:
      resourceClass - the class owning the resource
      resourceName - the resource name
      Returns:
      an icon
      Throws:
      IllegalArgumentException - in case the given resource was not found
    • setClipboard

      public static void setClipboard(@Nullable String string)
      Sets the given string as clipboard contents
      Parameters:
      string - the string to put on the clipboard
    • parentOfType

      public static <T> @Nullable T parentOfType(Class<T> clazz, @Nullable Component component)
      Searches the parent component hierarchy of the given component for an ancestor of the given type
      Type Parameters:
      T - the type of parent to find
      Parameters:
      clazz - the class of the parent to find
      component - the component
      Returns:
      the parent of the given component of the given type, null if none is found
    • parentWindow

      public static @Nullable Window parentWindow(@Nullable Component component)
      Finds the first component of type Window in the parent hierarchy of component. Note that if component is of type Window, it is returned.
      Parameters:
      component - the component
      Returns:
      the parent Window of the given component, null if none is found
    • parentFrame

      public static @Nullable JFrame parentFrame(@Nullable Component component)
      Finds the first component of type JFrame in the parent hierarchy of component. Note that if component is of type JFrame, it is returned.
      Parameters:
      component - the component
      Returns:
      the parent JFrame of the given component, null if none is found
    • parentDialog

      public static @Nullable JDialog parentDialog(@Nullable Component component)
      Finds the first component of type JDialog in the parent hierarchy of component. Note that if component is of type JDialog, it is returned.
      Parameters:
      component - the component
      Returns:
      the parent JDialog of the given component, null if none is found
    • disposeParentWindow

      public static boolean disposeParentWindow(@Nullable Component component)
      Finds the parent Window and disposes it if found. If no parent Window is found this method has no effect
      Parameters:
      component - the component which parent Window should be disposed
      Returns:
      true if a parent Window was found and disposed
    • systemLookAndFeelClassName

      public static String systemLookAndFeelClassName()
      Note that GTKLookAndFeel is overridden with MetalLookAndFeel, since JTabbedPane does not respect the 'TabbedPane.contentBorderInsets' setting, making hierachical tabbed panes look bad
      Returns:
      the default look and feel for the platform we're running on
    • systemOrCrossPlatformLookAndFeelEnabled

      public static boolean systemOrCrossPlatformLookAndFeelEnabled()
      Returns:
      true if the system or cross-platform look and feel is enabled
      See Also:
    • printFocusOwner

      public static void printFocusOwner()
      For focus debug purposes, prints the new and old values to the standard output when the 'focusOwner' value changes in the current keyboard focus manager.