Package org.jdesktop.swingx
Class SwingXUtilities
java.lang.Object
org.jdesktop.swingx.SwingXUtilities
A collection of utility methods for Swing(X) classes.
-
PENDING JW: think about location of this class and/or its methods, Options:
- move this class to the swingx utils package which already has a bunch of xxUtils
- move methods between xxUtils classes as appropriate (one window/comp related util)
- keep here in swingx (consistent with swingutilities in core)
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
adjustFocus
(JComponent component) static int
convertModifiersToDropAction
(int modifiers, int sourcActions) static <T> T
getAncestor
(Class<T> clazz, Component c) An improved version ofSwingUtilities.getAncestorOfClass(Class, Component)
.private static Component[]
(package private) static RepaintManager
getTranslucentRepaintManager
(RepaintManager delegate) Obtains aTranslucentRepaintManager
from the specified manager.static <T> T
invokeAndWait
(Callable<T> callable) A version ofSwingUtilities.invokeAndWait(Runnable)
that supports return values.static <T> FutureTask
<T> invokeLater
(Callable<T> callable) A version ofSwingUtilities.invokeLater(Runnable)
that supports return values.static boolean
isDescendingFrom
(Component focusOwner, Component parent) Returns whether the component is part of the parent's container hierarchy.static boolean
isUIInstallable
(Object property) Checks and returns whether the given property should be replaced by the UI's default value.static int
loc2IndexFileList
(JList list, Point point) (package private) static <C extends JComponent & BackgroundPaintable>
voidpaintBackground
(C comp, Graphics2D g) private static boolean
pointIsInActualBounds
(JList list, int index, Point point) static void
setComponentTreeBackground
(Component c, Color color) Sets the background for an entire component hierarchy to the specified color.static void
setComponentTreeEnabled
(Component c, boolean enabled) Enables or disables of the components in the tree starting withc
.static void
setComponentTreeFont
(Component c, Font font) Sets the font for an entire component hierarchy to the specified font.static void
setComponentTreeForeground
(Component c, Color color) Sets the foreground for an entire component hierarchy to the specified color.static void
setComponentTreeLocale
(Component c, Locale locale) Sets the locale for an entire component hierarchy to the specified locale.static void
setHtmlFont
(HTMLDocument doc, Font font) Sets the font used for HTML displays to the specified font.static void
setLeadAnchorWithoutSelection
(ListSelectionModel selectionModel, int lead, int anchor) Updates lead and anchor selection index without changing the selection.static boolean
shouldIgnore
(MouseEvent mouseEvent, JComponent component) static void
Updates the componentTreeUI of all top-level windows of the current application.static void
updateAllComponentTreeUIs
(Window window) Updates the componentTreeUI of the given window and all its owned windows, recursively.static void
updateMnemonicBinding
(JComponent c, String pressed) A helper for creating and updating key bindings for components with mnemonics.static void
updateMnemonicBinding
(JComponent c, String pressed, String released) A helper for creating and updating key bindings for components with mnemonics.
-
Field Details
-
STYLESHEET
-
-
Constructor Details
-
SwingXUtilities
private SwingXUtilities()
-
-
Method Details
-
updateMnemonicBinding
A helper for creating and updating key bindings for components with mnemonics. Thepressed
action will be invoked when the mnemonic is activated.TODO establish an interface for the mnemonic properties, such as
MnemonicEnabled
and change signature topublic static <T extends JComponent & MnemonicEnabled> void updateMnemonicBinding(T c, String pressed)
- Parameters:
c
- the component bindings to updatepressed
- the name of the action in the action map to invoke when the mnemonic is pressed- Throws:
NullPointerException
- if the component isnull
-
updateMnemonicBinding
A helper for creating and updating key bindings for components with mnemonics. Thepressed
action will be invoked when the mnemonic is activated and thereleased
action will be invoked when the mnemonic is deactivated.TODO establish an interface for the mnemonic properties, such as
MnemonicEnabled
and change signature topublic static <T extends JComponent & MnemonicEnabled> void updateMnemonicBinding(T c, String pressed, String released)
- Parameters:
c
- the component bindings to updatepressed
- the name of the action in the action map to invoke when the mnemonic is pressedreleased
- the name of the action in the action map to invoke when the mnemonic is released (if the action is a toggle style, then this parameter should benull
)- Throws:
NullPointerException
- if the component isnull
-
paintBackground
-
getChildren
-
setComponentTreeEnabled
Enables or disables of the components in the tree starting withc
.- Parameters:
c
- the starting componentenabled
-true
if the component is to enabled;false
otherwise
-
setComponentTreeLocale
Sets the locale for an entire component hierarchy to the specified locale.- Parameters:
c
- the starting componentlocale
- the locale to set
-
setComponentTreeBackground
Sets the background for an entire component hierarchy to the specified color.- Parameters:
c
- the starting componentcolor
- the color to set
-
setComponentTreeForeground
Sets the foreground for an entire component hierarchy to the specified color.- Parameters:
c
- the starting componentcolor
- the color to set
-
setComponentTreeFont
Sets the font for an entire component hierarchy to the specified font.- Parameters:
c
- the starting componentfont
- the font to set
-
setHtmlFont
Sets the font used for HTML displays to the specified font. Components that display HTML do not necessarily honor font properties, since the HTML document can override these values. CallingsetHtmlFont
after the data is set will force the HTML display to use the font specified to this method.- Parameters:
doc
- the HTML document to updatefont
- the font to use- Throws:
NullPointerException
- if any parameter isnull
-
updateAllComponentTreeUIs
public static void updateAllComponentTreeUIs()Updates the componentTreeUI of all top-level windows of the current application. -
updateAllComponentTreeUIs
Updates the componentTreeUI of the given window and all its owned windows, recursively.- Parameters:
window
- the window to update
-
invokeLater
A version ofSwingUtilities.invokeLater(Runnable)
that supports return values.- Type Parameters:
T
- the return type of the callable- Parameters:
callable
- the callable to execute- Returns:
- a future task for accessing the return value
- See Also:
-
invokeAndWait
public static <T> T invokeAndWait(Callable<T> callable) throws InterruptedException, InvocationTargetException A version ofSwingUtilities.invokeAndWait(Runnable)
that supports return values.- Type Parameters:
T
- the return type of the callable- Parameters:
callable
- the callable to execute- Returns:
- the value returned by the callable
- Throws:
InterruptedException
- if we're interrupted while waiting for the event dispatching thread to finish executingcallable.call()
InvocationTargetException
- if an exception is thrown while runningcallable
- See Also:
-
getAncestor
An improved version ofSwingUtilities.getAncestorOfClass(Class, Component)
. This method traversesJPopupMenu
invoker and uses generics to return an appropriately typed object.- Type Parameters:
T
- the type of ancestor to find- Parameters:
clazz
- the class instance of the ancestor to findc
- the component to start the search from- Returns:
- an ancestor of the correct type or
null
if no such ancestor exists. This method also returnsnull
if any parameter isnull
.
-
isDescendingFrom
Returns whether the component is part of the parent's container hierarchy. If a parent in the chain is of type JPopupMenu, the parent chain of its invoker is walked.- Parameters:
focusOwner
-parent
-- Returns:
- true if the component is contained under the parent's hierarchy, coping with JPopupMenus.
-
getTranslucentRepaintManager
Obtains aTranslucentRepaintManager
from the specified manager. If the current manager is aTranslucentRepaintManager
or aForwardingRepaintManager
that contains aTranslucentRepaintManager
, then the passed in manager is returned. Otherwise a new repaint manager is created and returned.- Parameters:
delegate
- the current repaint manager- Returns:
- a non-
null
TranslucentRepaintManager
- Throws:
NullPointerException
- ifdelegate
isnull
-
isUIInstallable
Checks and returns whether the given property should be replaced by the UI's default value.- Parameters:
property
- the property to check.- Returns:
- true if the given property should be replaced by the UI's default value, false otherwise.
-
setLeadAnchorWithoutSelection
public static void setLeadAnchorWithoutSelection(ListSelectionModel selectionModel, int lead, int anchor) Updates lead and anchor selection index without changing the selection. Note: this is cinvalid input: '&p''ed from SwingUtilities2 to not have any direct dependency.- Parameters:
selectionModel
- the selection model to change lead/anchorlead
- the lead selection indexanchor
- the anchor selection index
-
shouldIgnore
-
loc2IndexFileList
-
pointIsInActualBounds
-
adjustFocus
-
convertModifiersToDropAction
public static int convertModifiersToDropAction(int modifiers, int sourcActions)
-