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 儿媳买车妈妈祝福语简短
14 毕业送礼老师祝福语简短
15 同事辞职正常祝福语简短
16 恭贺新婚文案祝福语简短
17 金店立秋祝福语简短英文
18 婆婆高寿祝福语大全简短