1

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)

2 Answers 2

6

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.

Sign up to request clarification or add additional context in comments.

Comments

3

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.