Register / Log in

This might be our first language specific post that we’ve had on here, but this one is worth it for all of you Java developers out there.

Many of you are probably familiar with Java’s look and feels.  The default Metal L&F is pretty boring.  It was created in about 1995, and was great for the time.  However, it looks pretty old-fashioned and out of date now.  Many people started using the native look and feels.  For instance, on Windows, your program would look a whole lot like Windows.  On a Mac, your software would look a whole lot like a Mac.  These are nice, but aren’t consistent when your app moves from one platform to the next.

With Java 6 Update 10, they released a new cross platform L&F that is very impressive.  This L&F is called Nimbus.  Installing it in your app is extremely easy to do.  Before you create any GUI components, execute the following code.  This will check to see if Nimbus is available, and if it is, it will apply it.

try
{
    for(LookAndFeelInfo info : UIManager.getInstalledLookAndFeels())
    {
        if(info.getName().equals("Nimbus"))
        {
            UIManager.setLookAndFeel(info.getClassName());
            break;
        }
    }
}
catch(UnsupportedLookAndFeelException e)
{
    // do something intelligent here if you want
}
catch (ClassNotFoundException e)
{
    // do something intelligent here if you want
}
catch (InstantiationException e)
{
    // do something intelligent here if you want
}
catch (IllegalAccessException e)
{
    // do something intelligent here if you want
}

As an example, here’s a picture of a simple calculator program using the old Metal L&F.  It is the same on all platforms, but it looks unprofessional, like a student project.

 

A calculator program using the Metal L&F

A calculator program using the Metal L&F

The Windows Vista L&F is fairly nice, but is only available on Windows Vista.  Other operating systems look different.

a calculator program using the vista L&F

a calculator program using the vista L&F

The Nimbus L&F is the same on all operating systems, and looks very nice:

a calculator program using the Nimbus L&F

a calculator program using the Nimbus L&F

More information about Nimbus can be found at http://java.sun.com/docs/books/tutorial/uiswing/lookandfeel/nimbus.html

View Comments

blog comments powered by Disqus