Java swing如何获得系统外观?
该UIManager.getSystemLookAndFeelClassName()方法返回Swing应用程序的当前系统外观。SwingUtilities.updateComponentTreeUI()设置LAF后,请不要忘记调用该方法以更新当前应用程序的外观。
package org.nhooo.example.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(250, 250);
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.setTitle("System LAF Demo");
try {
// 将系统外观用于Swing应用程序
String className = UIManager.getSystemLookAndFeelClassName();
System.out.println("className = " + className);
UIManager.setLookAndFeel(className);
} catch (Exception e) {
e.printStackTrace();
}
SwingUtilities.updateComponentTreeUI(frame);
frame.setVisible(true);
}
}热门推荐
10 浪漫的生日祝福语简短
11 信耶稣的人祝福语简短
12 女朋友考试祝福语简短
13 38节贺卡简短祝福语
14 周年庆典祝福语致辞简短
15 创业失败返乡祝福语简短
16 朋友家住豪宅祝福语简短
17 50多岁生日简短祝福语
18 老哥出门祝福语简短语