mgarin / weblaf

WebLaF is a fully open-source Look & Feel and component library written in pure Java for cross-platform desktop Swing applications.
http://weblookandfeel.com
GNU General Public License v3.0
1.13k stars 234 forks source link

Rendering fonts under Apple M1 #665

Open mokun opened 3 years ago

mokun commented 3 years ago

Recently I've switched to using my new Apple mac mini with M1 CPU.

I have no problems running the core program.

However, as soon as I start the Swing windows which currently depends on Weblaf,

It could be just a font initialization error. It points to calling WebLookAndFeel.install() when it happens in my initializeWeblaf() in MainWindow.java

[pool-1-thread-1] ERROR com.alee.laf.NativeFonts - Unable to retrieve native Mac OS X font using method: com.apple.laf.AquaFonts.getControlTextFont()
java.lang.reflect.InaccessibleObjectException: Unable to make public static javax.swing.plaf.FontUIResource com.apple.laf.AquaFonts.getControlTextFont() accessible: module java.desktop does not "exports com.apple.laf" to unnamed module @7113b13f
    at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:357)
    at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
    at java.base/java.lang.reflect.Method.checkCanSetAccessible(Method.java:199)
    at java.base/java.lang.reflect.Method.setAccessible(Method.java:193)
    at com.alee.utils.ReflectUtils.getMethodImpl(ReflectUtils.java:1913)
    at com.alee.utils.ReflectUtils.getMethodImpl(ReflectUtils.java:1873)
    at com.alee.utils.ReflectUtils.getMethod(ReflectUtils.java:1842)
    at com.alee.utils.ReflectUtils.callStaticMethod(ReflectUtils.java:1467)
    at com.alee.utils.ReflectUtils.callStaticMethod(ReflectUtils.java:1421)
    at com.alee.laf.NativeFonts.getMacOSFont(NativeFonts.java:664)
    at com.alee.laf.NativeFonts.get(NativeFonts.java:271)
    at com.alee.laf.WebLookAndFeel.<clinit>(WebLookAndFeel.java:243)
    at org.mars_sim.msp.ui.swing.MainWindow.initializeWeblaf(MainWindow.java:1189)

Can you think of any possible workarounds for this situation with M1 ?

Thanks !

mgarin commented 3 years ago

This seems like an issue with newer Java version. You might have to add some extra JVM options to avoid it, I've mentioned it in the wiki article here: https://github.com/mgarin/weblaf/wiki/Java-9-and-higher

WebLaF is simply not able to access a proprietary method. This specific problem from the stack trace above should go away if you add this JVM option:

--add-opens java.desktop/com.apple.laf=ALL-UNNAMED

There is unfortunately no other way to workaround it right now - WebLaF has to use reflection to access multiple proprietary classes and methods to properly configure fonts, antialiasing and some other component settings.

I'm not sure if you've used any of these JVM options before and how it is related to switching to M1. My guess is - you simply have a newer JVM version (>=12) on your M1 that caused this issue to appear. On earlier JVM versions (<=11) reflection was not forcefully limited by default.

mokun commented 3 years ago

I'm not sure if you've used any of these JVM options before and how it is related to switching to M1. My guess is - you simply have a newer JVM version (>=12) on your M1 that caused this issue to appear. On earlier JVM versions (<=11) reflection was not forcefully limited by default.

Yes I just found out it that if I switch to using Java 11, instead of Java 15, the font problem in intelliJ for M1 goes away.

mgarin commented 3 years ago

But are you able to avoid the problem with the JVM options?