javaswingjframelook-and-feeluimanager

How to set jframe look and feel


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


Solution

  • 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