Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 809
Yayatcm Avatar asked Mar 02 '12 22:03

Yayatcm


People also ask

How do you set your look and feel?

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.

Which are 3 types of Look & Feel available in Swing?

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.


2 Answers

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

like image 87
Byron Voorbach Avatar answered Oct 21 '22 00:10

Byron Voorbach


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);
    }
like image 33
John Mercier Avatar answered Oct 20 '22 23:10

John Mercier