Java 本机操作系统外观Netbeans不能与UIManager.setLookAndFeel(nativeLF)配合使用;
我一直在网上(当然是:)查找以下问题。 Netbeans提供了一个“很棒”的默认外观,因此我想将其更改为本机外观。我的意思是,运行的程序看起来与设计的GUI不一样。因此,当您在Windows pc上设计时,该程序看起来像Windows,Mac等 所以,我在这个网站上搜索了很多次,发现了这样一个示例代码:Java 本机操作系统外观Netbeans不能与UIManager.setLookAndFeel(nativeLF)配合使用;,java,windows,user-interface,look-and-feel,netbeans-7.1,Java,Windows,User Interface,Look And Feel,Netbeans 7.1,我一直在网上(当然是:)查找以下问题。 Netbeans提供了一个“很棒”的默认外观,因此我想将其更改为本机外观。我的意思是,运行的程序看起来与设计的GUI不一样。因此,当您在Windows pc上设计时,该程序看起来像Windows,Mac等 所以,我在这个网站上搜索了很多次,发现了这样一个示例代码: private void setLookAndFeel() { // Get the native look and feel class name String nativeL
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行)
我希望有人能帮助我
提前谢谢
戴夫
背景资料:
-Netbeans 7.1.2
-视窗7
-不会这样工作:-
AWT
具有依赖于平台的外观和感觉,但Swing
没有
-如果您在AWT
中编写GUI,不需要额外的努力,您的代码将具有本机外观。
-您可以在Swing程序中使用setNativelook和feel
查看此链接:
当它位于窗户内时,上述内容将给窗户带来外观和感觉。如果在Linux中,那么Linux的外观和感觉。最好的使用方法是在main方法中,如下所示
*/
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();
}
}
}
如果您需要一个不会因操作系统而改变的外观,或者一些非常好的东西,请查看以下包含外观jar的链接
请修改代码示例,在调用getSystemLookAndFeelClassName之后和try块之前打印出nativeLF的值。价值是什么?好奇它是否为空。问题是:起初我调用了initComponents()方法,之后调用了上面给出的方法,但现在我先调用了setLookAndFeel()然后调用了initComponents()。@Dave:不客气,Dave。如果此答案解决了您的问题,请将此标记为答案,这样您的问题将进入已解决问题列表:)
*/
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();
}
}
}