简体   繁体   English

javafx JFXPanel嵌入Mac的swing应用程序崩溃

[英]javafx JFXPanel embeded in swing application crash in mac

The jfxpanel in a swing aplication crash once I run in mac. 我在Mac中运行后,jfxpanel在摆动应用程序崩溃。 It runs fine in windows but in mac below error come, looks like something to do with font, but not sure why, please help 它在Windows中运行良好,但在Mac中出现以下错误,看起来与字体有关,但不确定为什么,请帮助

Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
    at com.sun.t2k.MacFontFinder.initPSFontNameToPathMap(MacFontFinder.java:339)
    at com.sun.t2k.MacFontFinder.getAllAvailableFontFamilies(MacFontFinder.java:359)
    at com.sun.t2k.T2KFontFactory.getFontFamilyNames(T2KFontFactory.java:1056)
    at com.sun.prism.j2d.J2DFontFactory.getFontFamilyNames(J2DFontFactory.java:52)
    at com.sun.webpane.sg.prism.WCFontImpl.getFont(WCFontImpl.java:37)
    at com.sun.webpane.sg.prism.FXGraphicsManager.getWCFont(FXGraphicsManager.java:56)
    at com.sun.webpane.webkit.network.URLLoader.twkDidFinishLoading(Native Method)
    at com.sun.webpane.webkit.network.URLLoader.access$1300(URLLoader.java:44)
    at com.sun.webpane.webkit.network.URLLoader$6.run(URLLoader.java:691)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:76)
Invalid memory access of location 0x0 rip=0x11c8c7b64
Segmentation fault: 11

You are using a runtime environment that is not compatible with JavaFX. 您正在使用与JavaFX不兼容的运行时环境。

That is inadvisable. 这是不可取的。 A version of JavaFX compatible with Apple Java Runtime for Mac was never released. 从未发布过与MacApple Java Runtime兼容的JavaFX版本。 You should use Oracle Java 8+ or OpenJDK 8+ if you wish JavaFX for Mac to work correctly. 如果希望JavaFX for Mac正常运行,则应使用Oracle Java 8+或OpenJDK 8+。 If you cannot use one of those compatible runtimes then use of JavaFX is not recommended. 如果您不能使用这些兼容的运行时之一,则不建议使用JavaFX。

If you are using Apple Java for Mac because you are worried about a Java runtime for your application being available on the user machine, then consider packaging your application as a self-contained application , which embeds a compatible runtime with your application and does not rely on a pre-installed runtime. 如果您使用Apple Java for Mac是因为担心在用户计算机上可以使用应用程序的Java运行时,请考虑将应用程序打包为自包含应用程序 ,该应用程序将兼容的运行时嵌入到您的应用程序中,并且不依赖在预安装的运行时上。

have you tried this dirty hacking? 您是否尝试过这种肮脏的黑客行为? I read somewhere that this problem occurs in JDK 7 on OS X/el Capitan, but that it is very likely that it will never get fixed in JDK 7. 我在某处读到此问题发生在OS X / el Capitan上的JDK 7中,但很有可能永远无法在JDK 7中解决。

So I found this dirty hack, it works for me ... 所以我发现了这个肮脏的hack,对我有用...

    if (isMac()) {
        try {
            final Class<?> macFontFinderClass = Class.forName("com.sun.t2k.MacFontFinder");
            final Field psNameToPathMap = macFontFinderClass.getDeclaredField("psNameToPathMap");
            psNameToPathMap.setAccessible(true);
            if (psNameToPathMap.get(null) == null) {
                psNameToPathMap.set(
                    null, new HashMap<String, String>());
            }
            final Field allAvailableFontFamilies = macFontFinderClass.getDeclaredField("allAvailableFontFamilies");
            allAvailableFontFamilies.setAccessible(true);
            if (allAvailableFontFamilies.get(null) == null) {
                allAvailableFontFamilies.set(
                    null, new String[] {});
            }
        } catch (final Exception e) {
            // ignore
        }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM