2011-01-06 28 views
0

覺得我只是學習Java,仍然沒有能夠解決這一點問題,我有如何設置Nimbus的外觀和主要

我彈出日曆使用Nimbus的外觀和感覺,但我有板和容器JTable中 使用Java的外觀和感覺 - 我試圖讓每個GUI屏幕/窗口都使用nimbus外觀和感覺,並且Merky建議將愚蠢代碼放在我的主要 中,以使每個後續屏幕都具有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. 

      Cant get it to compile or work. 

} 

會apprciate一些幫助,請 西蒙

回答

0
+0

感謝TofuBear但我有一個看看那些我不明白whatAdd下面的代碼到事件派發線程創建圖形用戶界面(GUI)之前:手段。你能不能只糾正我的代碼? – 2011-01-06 17:29:38

+0

那麼,如果它不編譯,錯誤信息是什麼? – TofuBeer 2011-01-06 17:33:07

+0

SwingApplication();這是哪裏?編譯消息:解析文件結束 } //結束類BuyWriteInputsModel – 2011-01-06 17:38:57

11

這是我在我的主要方法,使雨雲做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。希望有所幫助。

1

我想嘗試:

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