2010-01-06 121 views
1

我在Netbeans IDE的幫助下使用Swings創建了Java中的GUI。Java Swing GUI - 問題

現在的問題是,當我點擊「預覽設計」時,GUI的外觀是我操作系統的外觀和感覺,例如Windows XP,但是當我點擊「運行」按鈕運行應用程序時, GUI的感覺是金屬的。

如何設置GUI的基調。 (這將是更更好,如果答案是w.r.t NetBeans IDE中)

回答

6

您希望UIManager類。

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 

會改變它的外表&覺得無論系統默認爲。您必須在構建任何UI對象之前調用它,void main(String[] args)是一個好地方。

3

在main方法,明確地告訴Swing中使用其中L &樓一拉

// Metal! Woo! 
try { 
    UIManager.setLookAndFeel(
     UIManager.getCrossPlatformLookAndFeelClassName()); 
} catch (Exception e) { } 

// Fit in. Be boring. 
try { 
    UIManager.setLookAndFeel(
     UIManager.getSystemLookAndFeelClassName()); 
} catch (Exception e) { }