-
Enhancement
-
Resolution: Fixed
-
P2
-
9
-
b124
Swing has some non public L&F like:
com.sun.java.swing.plaf.gtk.GTKLookAndFeel
com.sun.java.swing.plaf.motif.MotifLookAndFeel
com.sun.java.swing.plaf.windows.WindowsLookAndFeel
It was possible to create it in JDK 8 by reflection and check that it is supported:
----------
String lafName = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
Class lafClass = Class.forName(lafName);
LookAndFeel laf = (LookAndFeel) lafClass.newInstance();
System.out.println("L&F supported: " + laf.isSupportedLookAndFeel());
----------
It is not possible to do the same in JDK 9 with modularization the L&Fs classes are not exported:
---------------
Exception in thread "main" java.lang.IllegalAccessException: Class MotifLAFTest can not access a member of class com.sun.java.swing.plaf.motif.MotifLookAndFeel (module java.desktop) with modifiers "public", module java.desktop does not export com.sun.java.swing.plaf.motif to <unnamed module @2cb4c3ab>
at sun.reflect.Reflection.throwIllegalAccessException(java.base@9.0/Reflection.java:453)
at sun.reflect.Reflection.ensureMemberAccess(java.base@9.0/Reflection.java:128)
at java.lang.Class.newInstance(java.base@9.0/Class.java:520)
at MotifLAFTest.main(MotifLAFTest.java:10)
---------------
The only way to check that the L&F is supported is to set it and check the UnsupportedLookAndFeelException:
---------------
UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
---------------
However, it also install L&F even it is not necessary.
The request is to add isSupportedLookAndFeel(String className) method to the UIManager class.
One more use case is creating a L&F without installation to get it properties.
For example the following code gives:
---------------------
WindowsLookAndFeel winLAF = new WindowsLookAndFeel();
Font f = (Font) winLAF.getDefaults().get("Label.font");
---------------------
Exception in thread "main" java.lang.IllegalAccessError: class test.WinLAFTest (in unnamed module @0xcb5822) cannot access class com.sun.java.swing.plaf.windows.WindowsLookAndFeel (in module java.desktop) because module java.desktop does not export com.sun.java.swing.plaf.windows to unnamed module @0xcb5822
---------------------
com.sun.java.swing.plaf.gtk.GTKLookAndFeel
com.sun.java.swing.plaf.motif.MotifLookAndFeel
com.sun.java.swing.plaf.windows.WindowsLookAndFeel
It was possible to create it in JDK 8 by reflection and check that it is supported:
----------
String lafName = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
Class lafClass = Class.forName(lafName);
LookAndFeel laf = (LookAndFeel) lafClass.newInstance();
System.out.println("L&F supported: " + laf.isSupportedLookAndFeel());
----------
It is not possible to do the same in JDK 9 with modularization the L&Fs classes are not exported:
---------------
Exception in thread "main" java.lang.IllegalAccessException: Class MotifLAFTest can not access a member of class com.sun.java.swing.plaf.motif.MotifLookAndFeel (module java.desktop) with modifiers "public", module java.desktop does not export com.sun.java.swing.plaf.motif to <unnamed module @2cb4c3ab>
at sun.reflect.Reflection.throwIllegalAccessException(java.base@9.0/Reflection.java:453)
at sun.reflect.Reflection.ensureMemberAccess(java.base@9.0/Reflection.java:128)
at java.lang.Class.newInstance(java.base@9.0/Class.java:520)
at MotifLAFTest.main(MotifLAFTest.java:10)
---------------
The only way to check that the L&F is supported is to set it and check the UnsupportedLookAndFeelException:
---------------
UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
---------------
However, it also install L&F even it is not necessary.
The request is to add isSupportedLookAndFeel(String className) method to the UIManager class.
One more use case is creating a L&F without installation to get it properties.
For example the following code gives:
---------------------
WindowsLookAndFeel winLAF = new WindowsLookAndFeel();
Font f = (Font) winLAF.getDefaults().get("Label.font");
---------------------
Exception in thread "main" java.lang.IllegalAccessError: class test.WinLAFTest (in unnamed module @0xcb5822) cannot access class com.sun.java.swing.plaf.windows.WindowsLookAndFeel (in module java.desktop) because module java.desktop does not export com.sun.java.swing.plaf.windows to unnamed module @0xcb5822
---------------------
- relates to
-
JDK-4279876 The user should be able to explictily set look and feel
-
- Closed
-