0

I have been looking over the internet (expescially StackOverflow of course :) ) for the following issue. Netbeans offers a 'great' default look and feel, so i want to change that to a native look. With this I mean, the running program doesn't look equal to the designed GUI. So when youre designing on a Windows pc, the program looks like Windows, and so for Mac etc.

So, I searched on this website, found a lot of times an example code like this:

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

But... it wont work for me.

I 'll get a nullpointerexception, that is very long (584 lines).

I hope someone can help me.

Thanks in advance!

Dave

Backgroundinformation: - Netbeans 7.1.2 - Windows 7 - wont work like this: http://www.exampledepot.com/egs/javax.swing/LookFeelNative.html

Dave
  • 77
  • 1
  • 2
  • 10
  • Please modify your code sample to print out the value of nativeLF after the call to getSystemLookAndFeelClassName and before the try block. What is the value? Curious if it is null. – Guido Simone Oct 09 '12 at 17:19

2 Answers2

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

The above will give windows look and feel, when it is inside WINDOWS. If in Linux, then the Linux look and feel. Best place to use this is inside your main method, something like following

 */
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();
        }
    }
}

If you need a look and feel that doesn't change based on the OS, and something really nice, look at the following links which contains look and feel Jars

http://www.javootoo.com/

PeakGen
  • 21,894
  • 86
  • 261
  • 463
  • The problem was: at first I called the initComponents() method and after that the method given above, but now i called first the setLookAndFeel() and then initComponents(). – Dave Oct 09 '12 at 18:19
  • @Dave: You are welcome Dave. If this answer solved your problem, then please mark this as the answer, so your question will go to the list of solved questions :) – PeakGen Oct 09 '12 at 18:50
0

- AWT has a platform dependent look and feel, but Swing doesn't.

- If you code your GUI in AWT, with no extra effort , your code will have native look and feel.

- You can use setNativeLookAndFeel in Swing Programs.

See this link:

http://www.apl.jhu.edu/~hall/java/Swing-Tutorial/Swing-Tutorial-LAF.html

Kumar Vivek Mitra
  • 33,294
  • 6
  • 48
  • 75