The UIManager.getSystemLookAndFeelClassName()
method returns the current system LAF (Look and Feel) for Swing application. Do not forget to call the SwingUtilities.updateComponentTreeUI()
method after setting the LAF to update the current application look and feel.
package org.kodejava.swing;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.WindowConstants;
public class SystemLAFDemo {
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setSize(500, 500);
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.setTitle("System LAF Demo");
try {
// Use the system look and feel for the swing application
String className = UIManager.getSystemLookAndFeelClassName();
System.out.println("className = " + className);
UIManager.setLookAndFeel(className);
} catch (Exception e) {
e.printStackTrace();
}
SwingUtilities.updateComponentTreeUI(frame);
frame.setVisible(true);
}
}
Latest posts by Wayan (see all)
- How do I get number of each day for a certain month in Java? - September 8, 2024
- How do I get operating system process information using ProcessHandle? - July 22, 2024
- How do I sum a BigDecimal property of a list of objects using Java Stream API? - July 22, 2024