Class SwingUtilities
- All Implemented Interfaces:
SwingConstants
SwingUtilities. Splits the JDK surface
three ways:
- EDT primitives —
invokeLater(Runnable),invokeAndWait(Runnable),isEventDispatchThread()bottom out inUI.getCurrent(), the Vaadin UI-thread proxy. - Tree walks — ancestor / root-pane / window / class-named
lookups walk our emulator parent chain (
Component.getParent()) and resolve cleanly. The Rectangle math overloads (computeIntersection / Union / Difference,isRectangleContainingRectangle) and the mouse-button bit checks (isLeftMouseButtonet al.) are pure value-math and behave exactly as the JDK implementation. - Pixel / paint / accessibility / L&F surface — coordinate
conversions, deepest-component-at, paint, layoutCompoundLabel,
FontMetrics-based string width, accessibility queries, processKeyBindings
/ notifyAction key dispatch, UI input/action map plumbing, viewport
wrapper helpers, focus-owner walk, and
updateComponentTreeUIall WARN viaEHelper.onUnimplemented(String, String, Object...)and return safe defaults. These pieces of the JDK surface depend on machinery we don't have (a Graphics pipeline, a FontMetrics implementation, an L&F dispatcher, the AWT focus-traversal engine), so we surface the gap in the migration log instead of fabricating answers.
"EDT" maps onto "Vaadin UI thread context with the session lock." The
proxy is UI.getCurrent() != null: every legitimate
Swing-side codepath enters with a current UI (peer event listeners,
timer fires, worker process/done callbacks all funnel through
EHelper.callSwing(Runnable) which sets the UI). A background
thread the user spawned themselves has no current UI and so reports
"not on EDT" — matching Swing's model.
From a background thread, invokeLater(Runnable) / invokeAndWait(Runnable)
reach the EDT through the thread's EmulatorContext: the runnable
is delivered to the session's live UI the way a Timer fire or a
SwingWorker.done() is (EHelper.onSessionLiveUI(VaadinSession, Runnable)). The context
carries the session but never makes a UI current, so these calls cannot resolve
the EDT from UI.getCurrent() there. A thread with no context has no
session to deliver to and throws IllegalStateException
(D_invoke_from_background).
-
Field Summary
Fields inherited from interface SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST -
Method Summary
Modifier and TypeMethodDescriptionstatic Rectanglestatic Rectangle[]computeDifference(Rectangle rectA, Rectangle rectB) static RectanglecomputeIntersection(int x, int y, int width, int height, Rectangle dest) static intcomputeStringWidth(FontMetrics fm, String str) static RectanglecomputeUnion(int x, int y, int width, int height, Rectangle dest) static MouseEventconvertMouseEvent(Component source, MouseEvent sourceEvent, Component destination) static PointconvertPoint(Component source, int x, int y, Component destination) static PointconvertPoint(Component source, Point aPoint, Component destination) static voidstatic voidstatic RectangleconvertRectangle(Component source, Rectangle aRectangle, Component destination) static Componentstatic AccessiblegetAccessibleAt(Component c, Point p) static AccessiblegetAccessibleChild(Component c, int i) static intstatic intstatic AccessibleStateSetstatic ContainergetAncestorNamed(String name, Component c) Walksc's parent chain (starting atc.getParent()) and returns the first ancestor whosenamematchesname, ornullif none.static ContainergetAncestorOfClass(Class<?> clazz, Component c) Walksc's parent chain (starting atc.getParent()) and returns the first ancestor whose runtime class is assignable toclazz, ornullif none.static ComponentgetDeepestComponentAt(Component parent, int x, int y) static Rectanglestatic ComponentReturns the topmost ancestor ofc: either the firstWindowancestor or, if none, the topmost ancestor with no parent.static JRootPaneReturns theJRootPanethat containsc, ornullif none — the JDK's own body, reachable becauseRootPaneContaineris ported (D_hierarchy_parity).static ActionMapstatic InputMapgetUIInputMap(JComponent c, int condition) static ContainerJDK contract: returns parent unwrapped through aJViewport.static WindowWalksc's emulator parent chain and returns the firstWindowancestor (excludingcitself), ornullif none.static voidinvokeAndWait(Runnable runnable) Posts the runnable to the Vaadin UI thread and blocks the calling thread until it has run.static voidinvokeLater(Runnable runnable) Posts the runnable to the Vaadin UI thread asynchronously.static booleanstatic booleanstatic booleanstatic booleanstatic booleanstatic booleanstatic StringlayoutCompoundLabel(FontMetrics fm, String text, Icon icon, int verticalAlignment, int horizontalAlignment, int verticalTextPosition, int horizontalTextPosition, Rectangle viewR, Rectangle iconR, Rectangle textR, int textIconGap) static StringlayoutCompoundLabel(JComponent c, FontMetrics fm, String text, Icon icon, int verticalAlignment, int horizontalAlignment, int verticalTextPosition, int horizontalTextPosition, Rectangle viewR, Rectangle iconR, Rectangle textR, int textIconGap) static booleannotifyAction(Action action, KeyStroke ks, KeyEvent event, Object sender, int modifiers) static voidpaintComponent(Graphics g, Component c, Container p, int x, int y, int w, int h) static voidpaintComponent(Graphics g, Component c, Container p, Rectangle r) static booleanprocessKeyBindings(KeyEvent event) static voidreplaceUIActionMap(JComponent c, ActionMap map) static voidreplaceUIInputMap(JComponent c, int condition, InputMap map) static voidL&F dispatch is permanently deferred per R_match_swing_errors sub-bucket (b) — the styling story lives in a later Vaadin+CSS pass.static WindowAlias forgetWindowAncestor(Component)— same JDK contract.
-
Method Details
-
isEventDispatchThread
public static boolean isEventDispatchThread()- Returns:
truewhen called from a Vaadin UI thread context.
-
invokeLater
Posts the runnable to the Vaadin UI thread asynchronously. Runs inside aEHelper.callSwing(Runnable)virtual-thread continuation so the runnable can park on blocking dialogs (R_callswing_envelope envelope around every Swing-side event handler).From a background thread the runnable is dropped, silently, when the session has no live UI left — a closed tab has no EDT to run it on.
- Throws:
IllegalStateException- on a thread with neither a current UI nor anEmulatorContext— see class doc.
-
invokeAndWait
public static void invokeAndWait(Runnable runnable) throws InterruptedException, InvocationTargetException Posts the runnable to the Vaadin UI thread and blocks the calling thread until it has run. ThrowsIllegalStateExceptionwhen called from the EDT itself — under Swing this would deadlock (D_gap_severity_triage case 2: loom rescue trigger). Migrators surfaced by this throw should either move the call off the EDT or useinvokeLater(Runnable)for fire-and-forget dispatch."Has run" includes a modal dialog the runnable opens: the call returns once the user has answered it, as on the desktop.
- Throws:
IllegalStateException- when called from the EDT, or on a thread with noEmulatorContext— see class doc.InvocationTargetException- if the runnable throws.InterruptedException- if the wait is interrupted.BrowserSessionClosedError- if the session has no live UI to run the runnable on, or loses it while the runnable waits on a modal dialog — nothing would ever end the wait (R_match_swing_errors case (8))
-
getWindowAncestor
Walksc's emulator parent chain and returns the firstWindowancestor (excludingcitself), ornullif none. MirrorsSwingUtilities.getWindowAncestor(Component). -
windowForComponent
Alias forgetWindowAncestor(Component)— same JDK contract. -
getRootPane
Returns theJRootPanethat containsc, ornullif none — the JDK's own body, reachable becauseRootPaneContaineris ported (D_hierarchy_parity). The container test comes first and coverscitself, sogetRootPane(frame)answers the frame's root pane rather than walking past it. -
getRoot
-
isDescendingFrom
-
getAncestorOfClass
-
getAncestorNamed
-
getUnwrappedParent
JDK contract: returns parent unwrapped through aJViewport. We don't emulateJViewport(Vaadin scrolling doesn't go through a viewport peer), so this just returnsComponent.getParent(). -
isLeftMouseButton
-
isMiddleMouseButton
-
isRightMouseButton
-
isRectangleContainingRectangle
-
computeIntersection
-
computeUnion
-
computeDifference
-
getLocalBounds
-
convertPoint
-
convertPoint
-
convertRectangle
-
convertMouseEvent
public static MouseEvent convertMouseEvent(Component source, MouseEvent sourceEvent, Component destination) -
convertPointToScreen
-
convertPointFromScreen
-
getDeepestComponentAt
-
calculateInnerArea
-
findFocusOwner
-
computeStringWidth
-
layoutCompoundLabel
public static String layoutCompoundLabel(JComponent c, FontMetrics fm, String text, Icon icon, int verticalAlignment, int horizontalAlignment, int verticalTextPosition, int horizontalTextPosition, Rectangle viewR, Rectangle iconR, Rectangle textR, int textIconGap) -
layoutCompoundLabel
-
paintComponent
-
paintComponent
-
updateComponentTreeUI
L&F dispatch is permanently deferred per R_match_swing_errors sub-bucket (b) — the styling story lives in a later Vaadin+CSS pass. We WARN so migration logs surface the call site, but make no peer changes. -
processKeyBindings
-
notifyAction
-
replaceUIInputMap
-
replaceUIActionMap
-
getUIInputMap
-
getUIActionMap
-
getAccessibleIndexInParent
-
getAccessibleAt
-
getAccessibleStateSet
-
getAccessibleChildrenCount
-
getAccessibleChild
-