Amit
Amit

Reputation: 34803

Java Swing GUI - Problem

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)

Upvotes: 1

Views: 454

Answers (2)

Jonathan Feinberg
Jonathan Feinberg

Reputation: 45364

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.

Upvotes: 3

Kevin Montrose
Kevin Montrose

Reputation: 22611

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.

Upvotes: 6

Related Questions