2012-10-09 18 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

@戴夫:不客气,戴夫。如果这个答案解决了你的问题,那么请把这个标记为答案,所以你的问题将进入解决问题列表:) –