Is Java System Property "swing.defaultlaf" actually referenced in source?
Alexey Ivanov
alexey.ivanov at oracle.com
Thu Jun 19 19:07:43 UTC 2025
Hi Mark,
The default look and feel is Metal on all OS except for macOS where the
default is Aqua.
You can modify the default look and feel using the the
|swing.defaultlaf| property, and it works for me as expected. The
default look and feel of an application is initialised to the class in
the |swing.defaultlaf| property.
I ran a simple Java program on Windows:
> java DefaultLookAndFeel.java
[*The Java(tm) Look and Feel* - javax.swing.plaf.metal.MetalLookAndFeel]
com.sun.java.swing.plaf.windows.WindowsLookAndFeel
javax.swing.plaf.metal.MetalLookAndFeel
> java
-Dswing.defaultlaf=com.sun.java.swing.plaf.windows.WindowsLookAndFeel
DefaultLookAndFeel.java
[*The Microsoft Windows Look and Feel* -
com.sun.java.swing.plaf.windows.WindowsLookAndFeel]
com.sun.java.swing.plaf.windows.WindowsLookAndFeel
javax.swing.plaf.metal.MetalLookAndFeel
The |swing.defaultlaf| property is documented and is used in the
tutorial How to Set the Look and Feel
<https://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html>,
specifically the section Specifying the Look and Feel: Command Line
<https://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html#commandLine>
has two examples how to modify the default look and feel.
If set the value to a class that doesn't exist, I'll get an exception:
> java -Dswing.defaultlaf=NimbusLookAndFeel DefaultLookAndFeel.java
Exception in thread "main" java.lang.Error: Cannot load
NimbusLookAndFeel at
java.desktop/javax.swing.UIManager.initializeDefaultLAF(UIManager.java:1390)
at java.desktop/javax.swing.UIManager.initialize(UIManager.java:1501) at
java.desktop/javax.swing.UIManager.maybeInitialize(UIManager.java:1467)
at java.desktop/javax.swing.UIManager.getLookAndFeel(UIManager.java:492)
at DefaultLookAndFeel.main(DefaultLookAndFeel.java:5)
You can use these line numbers to study how default look and feel is
initialised.
Please note the client-libs-dev mailing list is not a support forum, it
is place to discuss /development of client libraries/.
--
Regards,
Alexey
On 2025-06-19 19:04, Ludwig, Mark wrote:
>
> Greetings,
>
> We are in the process of (finally) completing a migration from
> AWT-based windows and dialogs to Swing-based that was started in the
> 1990s.
>
> Testing the external Swing controls on Linux, we find nothing seems to
> happen as a result of setting the “swing.defaultlaf” System Property.
> This is documented in multiple places – at least the
> javax.swing.UIManager doc, and the *How to Set the Look and Feel*
> tutorial (and is mentioned in
> https://bugs.openjdk.org/browse/JDK-8159164).
>
> We find the “swing.systemlaf” System Property is effective in changing
> the returned value from UIManager.getSystemLookAndFeelClassName(), but
> does not by itself change the look-and-feel -- only with something
> like
> UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()),
> which is documented.
>
> We would appreciate clarity on this discrepancy regarding the
> “default” look-and-feel for Swing on Linux.
>
> Thanks,
>
> Mark Ludwig
>
The source of the sample app:
|import javax.swing.UIManager; public class DefaultLookAndFeel { public
static void main(String[] args) {
System.out.println(UIManager.getLookAndFeel());
System.out.println(UIManager.getSystemLookAndFeelClassName());
System.out.println(UIManager.getCrossPlatformLookAndFeelClassName()); } }|
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/client-libs-dev/attachments/20250619/9b312f8e/attachment-0001.htm>
More information about the client-libs-dev
mailing list