我刚刚学习Java,仍然无法解决我遇到的这个小问题。
我的弹出日历使用 Nimbus 外观和感觉,但我有使用 Java 外观和感觉的面板和容器 Jtable - 我试图使每个 GUI 屏幕/窗口都使用 Nimbus 外观和感觉。 Merky 建议将以下代码放在我的 main 中,以使后续的每个屏幕都具有 Nimbus 的外观和感觉,但我无法让它工作,那么我应该在哪里以及如何放置此代码?
public static void main(String args[]) {
SA md = new OptraderSA("Copyright© 2010 Simon Andi");
Dimension sd = Toolkit.getDefaultToolkit().getScreenSize();
md.setLocation(sd.width/2-400/2, sd.height/2-400/2);
md.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
/*Suggested Code*/
try {
for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
UIManager.setLookAndFeel(info.getClassName());
System.out.println("CHOSEN THIS");
break;
} else {
UIManager.setLookAndFeel ("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
}
}
} catch (Exception e) {
// If Nimbus is not available, you can set to another look and feel.
// I can't get it to compile or work.
}
}
这就是我在主要方法中所做的,以启用 Nimbus 的外观:
public static void main(String[] args) {
try {
for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (Exception e) {
// If Nimbus is not available, fall back to cross-platform
try {
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
} catch (Exception ex) {
// Not worth my time
}
}
new Controller();
}
在启动 swing 事件调度线程之前(在调用 view.setVisible(true) 之前),您需要确保使用 Nimbus 外观配置 UIManager。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)