Java自身UI界面太丑怎么办?通过在加载窗口时加入以下代码就可以将Java应用程序GUI设置成当前系统风格:
try {
// 设置本机系统外观
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
e.printStackTrace();
}
根据UIManager源程序,
private static LookAndFeelInfo[] installedLAFs;
static {
ArrayList<LookAndFeelInfo> iLAFs = new ArrayList<LookAndFeelInfo>(4);
iLAFs.add(new LookAndFeelInfo(
"Metal", "javax.swing.plaf.metal.MetalLookAndFeel"));
iLAFs.add(new LookAndFeelInfo(
"Nimbus", "javax.swing.plaf.nimbus.NimbusLookAndFeel"));
iLAFs.add(new LookAndFeelInfo("CDE/Motif",
"com.sun.java.swing.plaf.motif.MotifLookAndFeel"));
// Only include windows on Windows boxs.
OSInfo.OSType osType = AccessController.doPrivileged(OSInfo.getOSTypeAction());
if (osType == OSInfo.OSType.WINDOWS) {
iLAFs.add(new LookAndFeelInfo("Windows",
"com.sun.java.swing.plaf.windows.WindowsLookAndFeel"));
if (Toolkit.getDefaultToolkit().getDesktopProperty(
"win.xpstyle.themeActive") != null) {
iLAFs.add(new LookAndFeelInfo("Windows Classic",
"com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel"));
}
}
else if (osType == OSInfo.OSType.MACOSX) {
iLAFs.add(new LookAndFeelInfo("Mac OS X", "com.apple.laf.AquaLookAndFeel"));
}
else {
// GTK is not shipped on Windows.
iLAFs.add(new LookAndFeelInfo("GTK+",
"com.sun.java.swing.plaf.gtk.GTKLookAndFeel"));
}
installedLAFs = iLAFs.toArray(new LookAndFeelInfo[iLAFs.size()]);
}
想要更改为windows样式只需要
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
就可以了。