Home > database >  How do I modify a look and feel system class such as com.sun.java.swing.plaf.windows.WindowsTableHea
How do I modify a look and feel system class such as com.sun.java.swing.plaf.windows.WindowsTableHea

Time:02-12

I need to make a change to this class, there is no way for me to just subclass in normal way. So I can modify the java file (or make a copy of it) but how do I get my Swing application to use this version instead of the one provided by the Java runtime?

What I am trying to do is make a copy of com.sun.java.swing.plaf.windows.WindowsTableHeaderUI and fix it, so I cant just create a copy of the class sand put it into my own pacakage hierachy as I dont have access to many of the classes referred to in the class (such as XPStyle) so how do i replace the system class?

CodePudding user response:

So I got it working as follows:

  1. git clone https://github.com/AdoptOpenJDK/openjdk-jdk11.git

  2. Copied the following files from src/java.desktop/windows/classes/com/sun/java/swing/plaf/windows - WindowsTableHeaderUI.java, TMSchema.java, XPStyle.java into my code tree

  3. Modified the package statement for these three files to match they have been placed

  4. Added the following to allow the internal classes to be found

    --add-exports java.desktop/sun.awt.windows=ALL-UNNAMED

    --add-exports java.desktop/sun.awt.image=ALL-UNNAMED

    --add-exports java.desktop/sun.swing.table=ALL-UNNAMED

    --add-exports java.desktop/sun.swing=ALL-UNNAMED

    --add-exports java.desktop/com.sun.java.swing.plaf.windows=ALL-UNNAMED --add-exports java.base/sun.security.action=ALL-UNNAMED

  5. A few minor changes to allow classes to compile

  6. Implemented my fix for the WindowsTableHeaderUI class

  7. Used in application but only if on Windows with

     if(Platform.isWindows())
     {
          UIManager.put("TableHeaderUI","com.jthink.jaikoz.tablerenderer.windows.WindowsTableHeaderUI");
     }
    
  • Related