java.lang.Object
is.codion.swing.common.ui.Utilities
A utility class for UI related things.
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
collapseAll
(JTree tree, TreePath parent) Collapses all the paths from a parent in the given treestatic boolean
disposeParentWindow
(Component component) Finds the parent Window and disposes it if found.static void
Expands all the paths from a parent in the given treestatic void
linkBoundedRangeModels
(BoundedRangeModel main, BoundedRangeModel linked) Links the given BoundedRangeModels so that changes inmain
are reflected inlinked
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 activestatic 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 activestatic ImageIcon
Loads an icon as a resourcestatic JDialog
parentDialog
(Component component) Finds the first component of typeJDialog
in the parent hierarchy ofcomponent
.static JFrame
parentFrame
(Component component) Finds the first component of typeJFrame
in the parent hierarchy ofcomponent
.static <T> T
parentOfType
(Class<T> clazz, Component component) Searches the parent component hierarchy of the given component for an ancestor of the given typestatic Window
parentWindow
(Component component) Finds the first component of typeWindow
in the parent hierarchy ofcomponent
.static void
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.static <T> Observer<T>
propertyChangeEvent
(JComponent component, String property) Returns aObserver
notified each time the value of the given property changes in the given component.static void
setClipboard
(String string) Sets the given string as clipboard contentsstatic 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%static String
Note that GTKLookAndFeel is overridden with MetalLookAndFeel, since JTabbedPane does not respect the 'TabbedPane.contentBorderInsets' setting, making hierachical tabbed panes look badstatic boolean
static void
updateComponentTreeUI
(Collection<? extends JComponent> components) CallsSwingUtilities.updateComponentTreeUI(Component)
for the given components, ignores null components.static void
updateComponentTreeUI
(JComponent... components) CallsSwingUtilities.updateComponentTreeUI(Component)
for the given components, ignores null components.static void
updateUI
(Collection<? extends JComponent> components) CallsJComponent.updateUI()
for the given components, ignores null components.static void
updateUI
(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
-
updateComponentTreeUI
CallsSwingUtilities.updateComponentTreeUI(Component)
for the given components, ignores null components.- Parameters:
components
- the components to update the UI for
-
updateComponentTreeUI
CallsSwingUtilities.updateComponentTreeUI(Component)
for the given components, ignores null components.- Parameters:
components
- the components to update the UI for
-
linkToEnabledState
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
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
-
propertyChangeEvent
Returns aObserver
notified 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
Observer
notified each time the value of the given property changes
-
linkBoundedRangeModels
Links the given BoundedRangeModels so that changes inmain
are 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 typeWindow
in the parent hierarchy ofcomponent
. Note that ifcomponent
is 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 typeJFrame
in the parent hierarchy ofcomponent
. Note that ifcomponent
is 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 typeJDialog
in the parent hierarchy ofcomponent
. Note that ifcomponent
is 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.
-