<<< SwingMain.java     Index     SwingMain.java >>>

12. A3 Swing Look and Feel

  • Swing programs will start up in their own native look and feel rather than the Windows, Motif or Mac style

  • It is best to set the OS-specific system look and feel

  • The idea is to use UIManager.setLookAndFeel method

  • See next side for complete example

  • 
    // Setting OS-specific look and feel:
    private static void setSystemLookFeel()
    {
        // Force GUI to come up in the OS-specific look and feel
        String laf = UIManager.getSystemLookAndFeelClassName();
        try
        {
            UIManager.setLookAndFeel(laf);
        }
        catch ( UnsupportedLookAndFeelException exc )
        {
            System.err.println( "Unsupported: " + laf );
        }
        catch ( Exception exc )
        {
            System.err.println( "Error loading " + laf );
        }
    }
    
    

<<< SwingMain.java     Index     SwingMain.java >>>