Reputation: 34803
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
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
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