Domanda

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

È stato utile?

Soluzione

 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/

Altri suggerimenti

- 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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top