public final class SwingUtils
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.Object |
NOT_NULL |
Modifier and Type | Method and Description |
---|---|
static boolean |
equals(java.lang.Object obj1,
java.lang.Object obj2)
Convenience method for determining whether two objects are either
equal or both null.
|
static java.util.Map<javax.swing.JComponent,java.util.List<javax.swing.JComponent>> |
getComponentMap(javax.swing.JComponent container,
boolean nested)
Convenience method for mapping a container in the hierarchy to its
contained components.
|
static <T extends javax.swing.JComponent> |
getDescendantOfClass(java.lang.Class<T> clazz,
java.awt.Container container,
java.lang.String property,
java.lang.Object value)
Convenience method that searches below
container in the
component hierarchy in a depth first manner and returns the first
found component of class clazz having the bound property
value. |
static <T extends javax.swing.JComponent> |
getDescendantOfClass(java.lang.Class<T> clazz,
java.awt.Container container,
java.lang.String property,
java.lang.Object value,
boolean nested)
Convenience method that searches below
container in the
component hierarchy in a depth first manner and returns the first
found component of class clazz having the bound property
value. |
static <T extends javax.swing.JComponent> |
getDescendantOfType(java.lang.Class<T> clazz,
java.awt.Container container,
java.lang.String property,
java.lang.Object value)
Convenience method that searches below
container in the
component hierarchy and returns the first found component that is an
instance of class clazz having the bound property value. |
static <T extends javax.swing.JComponent> |
getDescendantOfType(java.lang.Class<T> clazz,
java.awt.Container container,
java.lang.String property,
java.lang.Object value,
boolean nested)
Convenience method that searches below
container in the
component hierarchy and returns the first found component that is an
instance of class clazz and has the bound property value. |
static <T extends javax.swing.JComponent> |
getDescendantsOfClass(java.lang.Class<T> clazz,
java.awt.Container container)
Convenience method for searching below
container in the
component hierarchy and return nested components of class
clazz it finds. |
static <T extends javax.swing.JComponent> |
getDescendantsOfClass(java.lang.Class<T> clazz,
java.awt.Container container,
boolean nested)
Convenience method for searching below
container in the
component hierarchy and return nested components of class
clazz it finds. |
static <T extends javax.swing.JComponent> |
getDescendantsOfType(java.lang.Class<T> clazz,
java.awt.Container container)
Convenience method for searching below
container in the
component hierarchy and return nested components that are instances of
class clazz it finds. |
static <T extends javax.swing.JComponent> |
getDescendantsOfType(java.lang.Class<T> clazz,
java.awt.Container container,
boolean nested)
Convenience method for searching below
container in the
component hierarchy and return nested components that are instances of
class clazz it finds. |
static <T extends javax.swing.JComponent> |
getJClass(T component)
Convenience method to obtain the Swing class from which this
component was directly or indirectly derived.
|
static java.util.Map<java.lang.Object,java.lang.Object> |
getProperties(javax.swing.JComponent component)
Convenience method for obtaining most non-null human readable properties
of a JComponent.
|
static java.lang.Object |
getUIDefaultOfClass(java.lang.Class clazz,
java.lang.String property)
Convenience method for retrieving the UIDefault for a single property
of a particular class.
|
static javax.swing.UIDefaults |
getUIDefaultsOfClass(java.lang.Class clazz)
Convenience method for retrieving a subset of the UIDefaults pertaining
to a particular class.
|
static javax.swing.UIDefaults |
getUIDefaultsOfClass(java.lang.String className)
Convenience method for retrieving a subset of the UIDefaults pertaining
to a particular class.
|
public static <T extends javax.swing.JComponent> java.util.List<T> getDescendantsOfType(java.lang.Class<T> clazz, java.awt.Container container)
container
in the
component hierarchy and return nested components that are instances of
class clazz
it finds. Returns an empty list if no such
components exist in the container.
Invoking this method with a class parameter of JComponent.class will return all nested components.
This method invokes getDescendantsOfType(clazz, container, true)
clazz
- the class of components whose instances are to be found.container
- the container at which to begin the searchpublic static <T extends javax.swing.JComponent> java.util.List<T> getDescendantsOfType(java.lang.Class<T> clazz, java.awt.Container container, boolean nested)
container
in the
component hierarchy and return nested components that are instances of
class clazz
it finds. Returns an empty list if no such
components exist in the container.
Invoking this method with a class parameter of JComponent.class will return all nested components.
clazz
- the class of components whose instances are to be found.container
- the container at which to begin the searchnested
- true to list components nested within another listed
component, false otherwisepublic static <T extends javax.swing.JComponent> T getDescendantOfType(java.lang.Class<T> clazz, java.awt.Container container, java.lang.String property, java.lang.Object value) throws java.lang.IllegalArgumentException
container
in the
component hierarchy and returns the first found component that is an
instance of class clazz
having the bound property value.
Returns null
if such component cannot be found.
This method invokes getDescendantOfType(clazz, container, property, value, true)
clazz
- the class of component whose instance is to be found.container
- the container at which to begin the searchproperty
- the className of the bound property, exactly as expressed in
the accessor e.g. "Text" for getText(), "Value" for getValue().value
- the value of the bound propertyjava.lang.IllegalArgumentException
- if the bound property does
not exist for the class or cannot be accessedpublic static <T extends javax.swing.JComponent> T getDescendantOfType(java.lang.Class<T> clazz, java.awt.Container container, java.lang.String property, java.lang.Object value, boolean nested) throws java.lang.IllegalArgumentException
container
in the
component hierarchy and returns the first found component that is an
instance of class clazz
and has the bound property value.
Returns null
if such component cannot be found.clazz
- the class of component whose instance to be found.container
- the container at which to begin the searchproperty
- the className of the bound property, exactly as expressed in
the accessor e.g. "Text" for getText(), "Value" for getValue().value
- the value of the bound propertynested
- true to list components nested within another component
which is also an instance of clazz
, false otherwisejava.lang.IllegalArgumentException
- if the bound property does
not exist for the class or cannot be accessedpublic static <T extends javax.swing.JComponent> java.util.List<T> getDescendantsOfClass(java.lang.Class<T> clazz, java.awt.Container container)
container
in the
component hierarchy and return nested components of class
clazz
it finds. Returns an empty list if no such
components exist in the container.
This method invokes getDescendantsOfClass(clazz, container, true)
clazz
- the class of components to be found.container
- the container at which to begin the searchpublic static <T extends javax.swing.JComponent> java.util.List<T> getDescendantsOfClass(java.lang.Class<T> clazz, java.awt.Container container, boolean nested)
container
in the
component hierarchy and return nested components of class
clazz
it finds. Returns an empty list if no such
components exist in the container.clazz
- the class of components to be found.container
- the container at which to begin the searchnested
- true to list components nested within another listed
component, false otherwisepublic static <T extends javax.swing.JComponent> T getDescendantOfClass(java.lang.Class<T> clazz, java.awt.Container container, java.lang.String property, java.lang.Object value) throws java.lang.IllegalArgumentException
container
in the
component hierarchy in a depth first manner and returns the first
found component of class clazz
having the bound property
value.
Returns null
if such component cannot be found.
This method invokes getDescendantOfClass(clazz, container, property, value, true)
clazz
- the class of component to be found.container
- the container at which to begin the searchproperty
- the className of the bound property, exactly as expressed in
the accessor e.g. "Text" for getText(), "Value" for getValue().
This parameter is case sensitive.value
- the value of the bound propertyjava.lang.IllegalArgumentException
- if the bound property does
not exist for the class or cannot be accessedpublic static <T extends javax.swing.JComponent> T getDescendantOfClass(java.lang.Class<T> clazz, java.awt.Container container, java.lang.String property, java.lang.Object value, boolean nested) throws java.lang.IllegalArgumentException
container
in the
component hierarchy in a depth first manner and returns the first
found component of class clazz
having the bound property
value.
Returns null
if such component cannot be found.
clazz
- the class of component to be found.container
- the container at which to begin the searchproperty
- the className of the bound property, exactly as expressed
in the accessor e.g. "Text" for getText(), "Value" for getValue().
This parameter is case sensitive.value
- the value of the bound propertynested
- true to include components nested within another listed
component, false otherwisejava.lang.IllegalArgumentException
- if the bound property does
not exist for the class or cannot be accessedpublic static boolean equals(java.lang.Object obj1, java.lang.Object obj2)
obj1
- the first reference object to compare.obj2
- the second reference object to compare.public static java.util.Map<javax.swing.JComponent,java.util.List<javax.swing.JComponent>> getComponentMap(javax.swing.JComponent container, boolean nested)
Implementation note: The returned value is a HashMap and the values are of type ArrayList. This is subject to change, so callers should code against the interfaces Map and List.
container
- The JComponent to be mappednested
- true to drill down to nested containers, false otherwisepublic static javax.swing.UIDefaults getUIDefaultsOfClass(java.lang.Class clazz)
clazz
- the class of interestpublic static javax.swing.UIDefaults getUIDefaultsOfClass(java.lang.String className)
className
- fully qualified name of the class of interestpublic static java.lang.Object getUIDefaultOfClass(java.lang.Class clazz, java.lang.String property)
clazz
- the class of interestproperty
- the property to querypublic static java.util.Map<java.lang.Object,java.lang.Object> getProperties(javax.swing.JComponent component)
Implementation note: The returned value is a HashMap. This is subject to change, so callers should code against the interface Map.
component
- the component whose proerties are to be determinedpublic static <T extends javax.swing.JComponent> java.lang.Class getJClass(T component)
component
- The component whose Swing superclass is to be
determined