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(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(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
    • linkToEnabledState

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

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

      public static <T> Observer<T> propertyChangeEvent(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
    • linkBoundedRangeModels

      public static void linkBoundedRangeModels(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
    • setFontSizePercentage

      public static void setFontSizePercentage(int fontSizePercentage)
      Sets a global font size percentage.
      85 = decrease the default font size by 15%
      100 = use the default font size
      125 = increase the default font size by 25%
      Parameters:
      fontSizePercentage - the font size percentage
    • setClipboard

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

      public static <T> T parentOfType(Class<T> clazz, 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 Window parentWindow(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 JFrame parentFrame(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 JDialog parentDialog(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(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.