Milchreis / UiBooster

🚀 Creates fast and easy dialogs for utility tools
GNU General Public License v3.0
117 stars 12 forks source link

GTKLookAndFeel error #55

Closed sgjava closed 3 months ago

sgjava commented 3 years ago

This is with your latest code. You may want to fix this before release. Try against JDK 17.

Running de.milchreis.uibooster.ThemeTest
java.lang.IllegalAccessException: class de.milchreis.uibooster.model.options.OSNativeUiBoosterOptions cannot access class com.sun.java.swing.plaf.gtk.GTKLookAndFeel (in module java.desktop) because module java.desktop does not export com.sun.java.swing.plaf.gtk to unnamed module @2a48d10f
    at java.base/jdk.internal.reflect.Reflection.newIllegalAccessException(Reflection.java:392)
    at java.base/java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:674)
    at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:489)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
    at de.milchreis.uibooster.model.options.OSNativeUiBoosterOptions.OSNativeLookAndFeel(OSNativeUiBoosterOptions.java:22)
Milchreis commented 3 years ago

Thank you. With OS do you use for it?

sgjava commented 3 years ago

Ubuntu 20.04.

Milchreis commented 3 years ago

Ok, I took some research. Since Java 9 you have to tell the compiler explicit which modules of the JDK are accessable. The module "java.desktop" contains the Swing classes. In the command line you can add --add-exports java.desktop/com.sun.java.swing.plaf=ALL-UNNAMED to make the module accessable.

I added this command to the pom.xml and it works, but only for Java 9 and higher. It seems, I have to make a decision: support native Look-and-Feel or support old Java 8 version.

In my case the UI falls back to the dark LAF. Do you have the same behaviour?

sgjava commented 3 years ago

So, you can use a profile in Maven too based on JDK http://www.avajava.com/tutorials/lessons/how-do-i-activate-a-profile-based-on-a-particular-version-of-java.html But honestly JDK 8 is pretty much EOL. JDK 11 has until 2023. I'm busy converting everything to JDK 17. LTS versions are the way to go.

Milchreis commented 3 months ago

I will close this issue, now. The main problem is the access to the java.desktop module, which contains the OS native LAF. The user has explicitly add --add-exports=java.desktop/com.sun.java.swing.plaf.windows=ALL-UNNAMED to the run command to use the native LAF, otherwise UiBooster catches the exception and uses the default dark LAF.