From b84dff21197c725289bbe0145d4ccf8a35098850 Mon Sep 17 00:00:00 2001 From: Kevin Rushforth Date: Fri, 5 Jan 2024 08:40:15 -0800 Subject: [PATCH] Search superclasses of JFXPanel in case app has subclassed it --- .../classes/sun/lwawt/macosx/CInputMethod.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/java.desktop/macosx/classes/sun/lwawt/macosx/CInputMethod.java b/src/java.desktop/macosx/classes/sun/lwawt/macosx/CInputMethod.java index f83bda20382a1..b5758c1138d98 100644 --- a/src/java.desktop/macosx/classes/sun/lwawt/macosx/CInputMethod.java +++ b/src/java.desktop/macosx/classes/sun/lwawt/macosx/CInputMethod.java @@ -99,16 +99,25 @@ private void trace(String meth) { */ } + private static final String JFXPANEL_CLASS_NAME = "javafx.embed.swing.JFXPanel"; + private static final Module desktopModule = Component.class.getModule(); + private boolean isJFXPanel(Component component) { - // FIXME: need a more robust way to determine this - return "javafx.embed.swing.JFXPanel".equals(component.getClass().getName()); + for (Class clazz = component.getClass(); clazz != null; clazz = clazz.getSuperclass()) { + if (desktopModule.equals(clazz.getModule())) { + // Stop searching once we have a class from the desktop module + return false; + } else if (JFXPANEL_CLASS_NAME.equals(clazz.getName())) { + return true; + } + } + return false; } private void invokeAndWaitIME(Runnable runnable, Component component) throws InvocationTargetException { if (isJFXPanel(component)) { - System.err.println("Detected JFXPanel...run directly"); runnable.run(); } else { LWCToolkit.invokeAndWait(runnable, component);