Change the Look & Feel of your Java App   #


import java.awt.BorderLayout; import java.awt.Label; import javax.swing.JFrame; import javax.swing.UIManager; /** * This snippet shows how to changes the look an feel of the gui application. * * @author mvohra * */ public class LookAndFeel { /** * Main Method * * @param args */ public static void main(String args[]) { try { // use one of the following method based on the desired look& feel // set the look & feel based on OS itself UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); // java metal look and feel works across platform UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); // set the Motif look and feel String motifClassName = "com.sun.java.swing.plaf.motif.MotifLookAndFeel"; UIManager.setLookAndFeel(motifClassName); // set the look & feel based on } catch (Exception e) { System.out.println("Error failed to set the Look & Feel" + e.getMessage()); e.printStackTrace(); } // rest of the gui code like creating frame etc. goes here // 1. Create the frame. JFrame frame = new JFrame("FrameDemo"); // 2. Optional: What happens when the frame closes? frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // 3. Create components and put them in the frame. // ...create emptyLabel... frame.getContentPane().add(new Label("See the Look and Feel"), BorderLayout.CENTER); // 4. Size the frame. frame.pack(); // 5. Show it. frame.setVisible(true); } }

Loading Please Wait...