0

I'm migrating a multiplatform (Windows and Linux) desktop application from java8 to OpenJDK 11. The code extends a Swing class and for that we define a new class that extends the WindowsTabbedPaneUI internal API class. This class is used when the application runs on Windows.

The code does the following:

   ...
   if (this.getUI() instanceof WindowsTabbedPaneUI) {
       this.setUI(new CustomWindowsTabbedPaneUI());
   }
   ...

where CustomWindowsTabbedPaneUI extends WindowsTabbedPaneUI.

This was working fine with java 8. However, now when I run on java 11 jre it throws the following exception:

java.lang.Exception: java.lang.NoClassDefFoundError: com/sun/java/swing/plaf/windows/WindowsTabbedPaneUI

I tried using the --add-opens and --add-exports options when launching the application but I could not make it work. I understand the reason is that the linux jre for java 11 does not include that class. I believe that's the case since running the command below does not list the com.sun.java.swing.plaf.windows package:

java --describe-module java.desktop

Any help is appreciated.

Sergio
  • 311
  • 1
  • 4
  • 7
  • maybe [Swing Issue on Java 10](https://stackoverflow.com/q/51555030/85421) – user85421 Oct 08 '19 at 18:11
  • Thanks Carlos. I read that post. However, that indicates how to address the problem at compile time, which just pushes the problem at runtime (see https://blog.codefx.org/java/five-command-line-options-hack-java-module-system/). What I need now is a solution at run time. – Sergio Oct 08 '19 at 19:07
  • 1
    If your app is multi-platform **and** contains Windows specific code, it must also contain linux specific code, no? So you would have the same issue with linux specific classes that are removed from the JDK. – Abra Oct 08 '19 at 19:24
  • It was using the base look & feel for linux, by extending from BasicTabbedPaneUI. But you are right, since I plan to use the Metal look and feel now. – Sergio Oct 09 '19 at 15:17
  • Simply check for the base non-internal class `BasicTabbedPaneUI` instead. Maybe with a check on Windows if so desired. – Joop Eggen Oct 11 '19 at 14:56
  • Thanks to all. I ended up extending BasicTabbedPaneUI. – Sergio Oct 16 '19 at 20:25

0 Answers0