java.lang.Object
is.codion.swing.common.ui.Utilities
A utility class for UI related things.
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidcollapseAll(JTree tree, TreePath parent) Collapses all the paths from a parent in the given treestatic booleandisposeParentWindow(Component component) Finds the parent Window and disposes it if found.static voidExpands all the paths from a parent in the given treestatic voidlinkBoundedRangeModels(BoundedRangeModel main, BoundedRangeModel linked) Links the given BoundedRangeModels so that changes inmainare reflected inlinkedstatic voidlinkToEnabledState(is.codion.common.state.StateObserver enabledState, Action... actions) Links the given actions to the given StateObserver, so that the actions are enabled only when the observed state is activestatic voidlinkToEnabledState(is.codion.common.state.StateObserver enabledState, JComponent... components) Links the given components to the given StateObserver, so that each component is enabled only when the observed state is activestatic ImageIconLoads an icon as a resourcestatic JDialogparentDialog(Component component) Finds the first component of typeJDialogin the parent hierarchy ofcomponent.static JFrameparentFrame(Component component) Finds the first component of typeJFramein the parent hierarchy ofcomponent.static <T> TparentOfType(Class<T> clazz, Component component) Searches the parent component hierarchy of the given component for an ancestor of the given typestatic WindowparentWindow(Component component) Finds the first component of typeWindowin the parent hierarchy ofcomponent.static voidFor focus debug purposes, prints the new and old values to the standard output when the 'focusOwner' value changes in the current keyboard focus manager.static <T> is.codion.common.event.EventObserver<T>propertyChangeObserver(JComponent component, String property) Returns aEventObservernotified each time the value of the given property changes in the given component.static voidsetClipboard(String string) Sets the given string as clipboard contentsstatic voidsetFontSizePercentage(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%static StringNote that GTKLookAndFeel is overridden with MetalLookAndFeel, since JTabbedPane does not respect the 'TabbedPane.contentBorderInsets' setting, making hierachical tabbed panes look badstatic booleanstatic voidupdateUI(Collection<? extends JComponent> components) CallsJComponent.updateUI()for the given components, ignores null components.static voidupdateUI(JComponent... components) CallsJComponent.updateUI()for the given components, ignores null components.
-
Method Details
-
updateUI
CallsJComponent.updateUI()for the given components, ignores null components.- Parameters:
components- the components to update the UI for
-
updateUI
CallsJComponent.updateUI()for the given components, ignores null components.- Parameters:
components- the components to update the UI for
-
linkToEnabledState
public static void linkToEnabledState(is.codion.common.state.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 actionactions- the actions
-
linkToEnabledState
public static void linkToEnabledState(is.codion.common.state.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 componentscomponents- the components
-
propertyChangeObserver
public static <T> is.codion.common.event.EventObserver<T> propertyChangeObserver(JComponent component, String property) Returns aEventObservernotified each time the value of the given property changes in the given component.- Type Parameters:
T- the property data type- Parameters:
component- the componentproperty- the property to listen to changes for- Returns:
- a
EventObservernotified each time the value of the given property changes
-
linkBoundedRangeModels
Links the given BoundedRangeModels so that changes inmainare reflected inlinked- Parameters:
main- the main modellinked- the model to link with main
-
expandAll
Expands all the paths from a parent in the given tree- Parameters:
tree- the treeparent- the parent from which to exapand
-
collapseAll
Collapses all the paths from a parent in the given tree- Parameters:
tree- the treeparent- the parent from which to collapse
-
loadIcon
Loads an icon as a resource- Parameters:
resourceClass- the class owning the resourceresourceName- 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
Sets the given string as clipboard contents- Parameters:
string- the string to put on the clipboard
-
parentOfType
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 findcomponent- the component- Returns:
- the parent of the given component of the given type, null if none is found
-
parentWindow
Finds the first component of typeWindowin the parent hierarchy ofcomponent. Note that ifcomponentis of typeWindow, it is returned.- Parameters:
component- the component- Returns:
- the parent Window of the given component, null if none is found
-
parentFrame
Finds the first component of typeJFramein the parent hierarchy ofcomponent. Note that ifcomponentis of typeJFrame, it is returned.- Parameters:
component- the component- Returns:
- the parent JFrame of the given component, null if none is found
-
parentDialog
Finds the first component of typeJDialogin the parent hierarchy ofcomponent. Note that ifcomponentis of typeJDialog, it is returned.- Parameters:
component- the component- Returns:
- the parent JDialog of the given component, null if none is found
-
disposeParentWindow
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
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.
-