I am kind of confused on where to put this :
try {
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
} catch(Exception e){
}
I did not extend the JFrame
class but used JFrame f = new JFrame();
Thanks :D
To programmatically specify a L&F, use the UIManager. setLookAndFeel() method with the fully qualified name of the appropriate subclass of LookAndFeel as its argument.
Default is "Java LAF" (or "Metal"), a custom look and feel similar to the Windows look. 2. Motif look available on all platforms. Windows and Mac looks are only available on their native platforms.
Most common place to put this, is right inside your static void main(String[] args) method. Like so:
public static void main(String[] args) {
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
} catch(Exception ignored){}
new YourClass(); //start your application
}
for more info look at this site: http://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
UIManager.setLookAndFeel()
will not work on components that are already created. Here is a good way to set the Look And Feel for every window in your application. This will set it on all open Windows in your program. Any new windows created will use what was set by the UIManager.
UIManager.setLookAndFeel(lookModel.getLookAndFeels().get(getLookAndFeel()));
for(Window window : JFrame.getWindows()) {
SwingUtilities.updateComponentTreeUI(window);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With