如何设置Nimbus的主要外观

我只是在学习Java,但仍然无法解决我遇到的这个小问题

我的弹出日历使用Nimbus的外观和感觉,但我有使用Java的外观和感觉的面板和容器Jtables – 我试图让每个GUI屏幕/窗口使用灵气的外观和感觉,并且Merky建议使用愚蠢的代码在我的主要使每个后续的屏幕都具有Nimbus的外观和感觉,但我不能让它工作,所以有人可以告诉我在哪里以及如何把这个代码请PLEASE。

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. Cant get it to compile or work. } 

请给我一些帮助请西蒙

这就是我在启用Nimbus L&F的主要方法中所做的。

 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 L&F配置UIManager。 希望有所帮助。

我想尝试:

 for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { UIManager.setLookAndFeel(info.getClassName()); System.out.println("CHOSEN THIS"); break; } 

要设置Nimbus外观,请在main方法中添加此代码

  try { for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (Exception e) { e.printStackTrace(); }