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
    • visible

      public static void visible(ObservableState visibleState, JComponent... components)
      Links the given components to the given ObservableState, so that each component is visible only when the observed state is active
      Parameters:
      visibleState - the ObservableState with which to link the components
      components - the components
    • focusable

      public static void focusable(ObservableState focusableState, JComponent... components)
      Links the given components to the given ObservableState, so that each component is focusable only when the observed state is active
      Parameters:
      focusableState - 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
    • 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
    • printFocusOwner

      public static void printFocusOwner(Function<JComponent,String> formatter)
      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.

      Note that calling this method for a second time has no effect.

      Parameters:
      formatter - formats the component in the output, only called for non-null components