tags:

views:

62

answers:

2

I have created a GUI in Java using swings with the help of Netbeans IDE.

Now the problem is when I click on "Preview Design", the look and feel of the GUI is that of my O.S i.e Windows XP but when I click on "Run" button to run the application, then the look and feel of the GUI is metalic.

How can I set the tone of the GUI. (It would be more better if the answer is w.r.t Netbeans IDE)

+6  A: 

You want the UIManager class.

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

Will change the Look & Feel to whatever the default on the system is. You have to call it before you construct any UI objects, void main(String[] args) is a good place.

Kevin Montrose
+3  A: 

In your main method, explicitly tell Swing which L&F to use, a la

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

or

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

etc.

Jonathan Feinberg