We need you!

We're working hard on the next version of Developer Fusion. Let us know what you think we should be up to!

Members

Technology Zones

Articles

Hosted By

MaximumASP

Info

Rated
Read 24,861 times

Contents

Related Categories

Programming with Swing - GUI Look & Feel

Michael H

GUI Look & Feel

Look And Feel is very important, it defines how components look and act (feel) . For instance, what you've been seeing when you have been putting components on a JPanel is the Java Look And Feel. The JButtons don't look normal, do they? Nope. Just like how Windows program looks different from a Java or Mac program, that's look and feel. A Java program typically can have one of the 5 or so possible LAFs(Look And Feels) :

  • Use the current OS's Look and Feel.
  • Use the Java (a.k.a Metal) Look and Feel.
  • Use the Motif (UNIX) Look and Feel.
  • Use the Windows LAF (only on windows).
  • Use the Mac LAF (only on mac).

To set the look and feel BEFORE constructing any components, use the UIManager class. It contains the setLookAndFeel(String classname) method that (as shown) takes a string that is the class name of the LAF that you want to use for your program.

Here's the code to use the Motif LAF:

Try {
    UIManager.setLookAndFeel("com.sun.java.swing.motif.MotifLookAndFeel");
}
catch(ClassNotFoundException e) {}

Here's the code to use the current OS's LAF:

Try {
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch(ClassNotFoundException e) {}

The Windows LAF Class Name is com.sun.java.swing.windows.WindowsLookAndFeel
The Mac LAF Class Name is com.sun.java.swing.mac.MacLookAndFeel
The Java LAF Class Name is com.sun.java.swing.plaf.metal.MetalLookAndFeel
To use the Java LAF (even though it IS the default) use the method UIManager.getCrossPlatformLookAndFeelClassName()

That's it for Look and Feel. If you manage to find other LAFs on the web. They are used in the same way, just find out its class name!

Comments

  • Closing button on internal frame

    Posted by manojacharya on 14 Nov 2005

    Hello,
    I want to add a closing button to the internal frame. I am not able to do it. Plz help.javascript:smilie(':confused:')
    confused

  • Java - MDI - ChildFrames

    Posted by BG3000 on 28 Oct 2004

    Hi.

    I have an ChildFrame inside of an DesktopFrame. I want to insert a JButton into the ChildFrame. But this JButton turns out to be very tiny in that child frame. If I maximize the child frame, t...

  • Posted by munas on 13 Sep 2004

    jho....

    just call your child frames as follows

    public class MainFrame extends JFrame
    {
    ChildFrame1 child1;
    public MainFrame()
    {
    final JDesktopPane desktop = new JDesktopPane();
    ...

  • JAVA MDI

    Posted by jho on 05 Aug 2004

    i have a JFrame named MainFrame which also uses JDesktoPane. I created 2 JInternalFrame class named ChildFrame1 and ChildFrame2. When I can click the menu on the mainframe, it shows the childframe1. I...