public final class CoreSwingUtils extends Object
| Modifier and Type | Method and Description |
|---|---|
static void |
enableEventQueueLogging()
Enables logging of all uncaught exceptions occurred within EDT.
|
static Rectangle |
getBoundsInWindow(Component component)
Returns component bounds inside its window.
|
static Rectangle |
getBoundsOnScreen(Component component,
boolean visibleOnly)
Returns
Component bounds on screen, either only visible or complete ones. |
static AWTEvent |
getCurrentEvent()
Returns current
EventQueue AWTEvent. |
static int |
getCurrentEventModifiers()
Returns current
EventQueue AWTEvent modifiers. |
static Point |
getMouseLocation()
Returns mouse location on the screen.
|
static Point |
getMouseLocation(Component component)
Returns mouse location on the screen relative to specified component.
|
static JRootPane |
getNonNullRootPane(Component component)
Returns root pane for the specified component or
null if it doesn't exist. |
static Window |
getNonNullWindowAncestor(Component component)
|
static PointerInfo |
getPointerInfo()
Returns pointer information.
|
static List<JPopupMenu> |
getPopupMenus()
Returns
List of displayed JPopupMenus. |
static Rectangle |
getRelativeBounds(Component component,
Component relativeTo)
Returns component bounds relative to another component.
|
static Point |
getRelativeLocation(Component component,
Component relativeTo)
Returns component location relative to another component.
|
static JRootPane |
getRootPane(Component component)
Returns root pane for the specified component or
null if it doesn't exist. |
static Component |
getTopComponentAt(Component component,
int x,
int y)
Returns top component inside the specified container component at the specified point.
|
static Component |
getTopComponentAt(Component component,
Point point)
Returns top component inside the specified container component at the specified point.
|
static Rectangle |
getVisibleRect(Component component)
Returns intersection of the visible rectangles for the component and all of its ancestors.
|
static Window |
getWindowAncestor(Component component)
|
static Insets |
getWindowDecorationInsets(Window window)
Returns window decoration insets.
|
static void |
invokeAndWait(Runnable runnable)
Will invoke the specified
Runnable in EDT in case it is called from non-EDT thread. |
static void |
invokeAndWait(Runnable runnable,
boolean ignoreInterrupts)
Will invoke the specified
Runnable in EDT in case it is called from non-EDT thread. |
static void |
invokeLater(Runnable runnable)
Will invoke specified
Runnable later in EDT. |
static void |
invokeOnEventDispatchThread(Runnable runnable)
|
static boolean |
isAncestorOf(Component ancestor,
Component component)
Returns whether or not specified
ancestor is an ancestor of component. |
static boolean |
isEventDispatchThread()
Returns whether or not current thread is an AWT event dispatching thread.
|
static boolean |
isFullScreen(Component component)
Returns whether or not specified component is placed on a fullscreen window.
|
static boolean |
isHovered(Component component)
Returns whether or not specified
Component is currently hovered. |
static boolean |
isMenuShortcutKeyDown(InputEvent event)
Returns whether or not specified
InputEvent contains a menu shortcut key. |
static boolean |
isSameAncestor(Component component1,
Component component2)
Returns whether specified components have the same ancestor or not.
|
static boolean |
isVisibleOnScreen(Component component)
Returns whether or not specified
Component is actually visible on screen. |
static Point |
locationOnScreen(Component component)
Returns
Component location on screen. |
public static void enableEventQueueLogging()
@Nullable public static AWTEvent getCurrentEvent()
EventQueue AWTEvent.EventQueue AWTEventpublic static int getCurrentEventModifiers()
EventQueue AWTEvent modifiers.EventQueue AWTEvent modifiers@NotNull public static Window getNonNullWindowAncestor(@NotNull Component component)
@NotNull public static JRootPane getNonNullRootPane(@NotNull Component component)
null if it doesn't exist.component - component to look undernull if it doesn't exist@Nullable public static JRootPane getRootPane(@Nullable Component component)
null if it doesn't exist.component - component to look undernull if it doesn't existpublic static boolean isVisibleOnScreen(@NotNull Component component)
Component is actually visible on screen.
Note that this method does not account for any other windows that may overlay current one, that needs to be checked separately.@NotNull public static Rectangle getBoundsOnScreen(@NotNull Component component, boolean visibleOnly)
@Nullable public static Rectangle getBoundsInWindow(@NotNull Component component)
component - component to process@NotNull public static Rectangle getRelativeBounds(@NotNull Component component, @NotNull Component relativeTo)
component - component to processrelativeTo - component relative to which bounds will be returned@NotNull public static Point getRelativeLocation(@NotNull Component component, @NotNull Component relativeTo)
component - component to processrelativeTo - component relative to which location will be returnedpublic static boolean isAncestorOf(@Nullable Component ancestor, @Nullable Component component)
ancestor is an ancestor of component.ancestor - ancestor componentcomponent - child componenttrue if specified ancestor is an ancestor of component, false otherwisepublic static boolean isSameAncestor(@Nullable Component component1, @Nullable Component component2)
component1 - first componentcomponent2 - second component@NotNull public static Insets getWindowDecorationInsets(@Nullable Window window)
window - window to retrieve insets forpublic static boolean isFullScreen(@Nullable Component component)
component - component to process@NotNull public static PointerInfo getPointerInfo()
@NotNull public static Point getMouseLocation()
@NotNull public static Point getMouseLocation(@NotNull Component component)
component - componentpublic static boolean isHovered(@NotNull Component component)
Component is currently hovered.@Nullable public static Component getTopComponentAt(@Nullable Component component, @NotNull Point point)
component - container component to processpoint - point on the component@Nullable public static Component getTopComponentAt(@Nullable Component component, int x, int y)
component - container component to processx - X coordinate on the componenty - Y coordinate on the component@NotNull public static List<JPopupMenu> getPopupMenus()
List of displayed JPopupMenus.
Multiple JPopupMenus can be displayed in case when submenus are visible.List of displayed JPopupMenuspublic static boolean isMenuShortcutKeyDown(@NotNull InputEvent event)
InputEvent contains a menu shortcut key.event - InputEventtrue if specified InputEvent contains a menu shortcut key, false otherwisepublic static boolean isEventDispatchThread()
true if the current thread is an AWT event dispatching thread, false otherwisepublic static void invokeLater(@NotNull Runnable runnable)
Runnable later in EDT.
It is highly recommended to perform all UI-related operations within EDT by invoking them through this method.runnable - Runnable to executepublic static void invokeOnEventDispatchThread(@NotNull Runnable runnable)
Runnable on the current Thread if it is Event Dispatch Thread.
Otherwise specified Runnable will be executed later on Event Dispatch Thread.runnable - Runnable to executepublic static void invokeAndWait(@NotNull Runnable runnable)
Runnable in EDT in case it is called from non-EDT thread.
It will catch any exceptions thrown by SwingUtilities.invokeAndWait(Runnable) and wrap them in UtilityException.
It is generally recommended to use invokeLater(Runnable) instead whenever it is possible to avoid stalling EDT.runnable - Runnable to executepublic static void invokeAndWait(@NotNull Runnable runnable, boolean ignoreInterrupts)
Runnable in EDT in case it is called from non-EDT thread.
It will catch any exceptions thrown by SwingUtilities.invokeAndWait(Runnable) and wrap them in UtilityException.
It is generally recommended to use invokeLater(Runnable) instead whenever it is possible to avoid stalling EDT.runnable - Runnable to executeignoreInterrupts - whether or not InterruptedExceptions should be ignored@NotNull public static Rectangle getVisibleRect(@NotNull Component component)
component - ComponentCopyright © 2020. All rights reserved.