2012-10-09 43 views
0

我一直在尋找互聯網(當然是經濟實惠的StackOverflow :))以下問題。 Netbeans提供了一個'很棒'的默認外觀和感覺,所以我想將其改爲原生外觀。我的意思是,正在運行的程序看起來不像設計的GUI。因此,當您選擇設計在Windows PC上,程序看起來像Windows,因此適用於Mac等本機操作系統的外觀和感覺Netbeans不適用於UIManager.setLookAndFeel(nativeLF);

所以,我搜索這個網站上,發現了很多的時間的示例代碼:

private void setLookAndFeel() { 
    // Get the native look and feel class name 
    String nativeLF = UIManager.getSystemLookAndFeelClassName(); 
    try { 
     UIManager.setLookAndFeel(nativeLF); 
    } catch (ClassNotFoundException | InstantiationException | 
IllegalAccessException | UnsupportedLookAndFeelException ex) { 
     Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex); 
    } 
} 

source: http://www.exampledepot.com/egs/javax.swing/LookFeelNative.html 

但是...它不會爲我工作。

我會得到一個nullpointerexception,這是很長的(584行)。

我希望有人能幫助我。

在此先感謝!

戴夫

Backgroundinformation: - Netbeans的7.1.2 - Windows 7的 - 不會以這種方式工作:http://www.exampledepot.com/egs/javax.swing/LookFeelNative.html

+0

請修改您的代碼示例調用getSystemLookAndFeelClassName和try塊之前後打印出來nativeLF的價值。什麼是價值?好奇,如果它是空的。 –

回答

2
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 

以上將給窗口的外觀和感覺,當它是Windows內部。如果在Linux中,那麼Linux的外觀和感覺。使用這個最好的地方是你的主要方法裏,像下面

*/ 
public class MyPhoneBookApp { 

    /** 
    * @param args the command line arguments 
    */ 
    public static void main(String[] args) 
    { 
     try 
     { 
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 
      new MainForm(); 
     } 
     catch(Exception e) 
     { 
      e.printStackTrace(); 
     } 
    } 
} 

如果你需要一個外觀和感覺,不基於OS改變,東西真的很好,看它包含以下鏈接外觀和感覺罐子

http://www.javootoo.com/

+0

謝謝!這個對我有用。 – Dave

+0

問題是:起初我調用了initComponents()方法,之後給出了上面給出的方法,但現在我先調用setLookAndFeel()然後調用initComponents()。 – Dave

+0

@戴夫:不客氣,戴夫。如果這個答案解決了你的問題,那麼請把這個標記爲答案,所以你的問題將進入解決問題列表:) –