tags:

views:

818

answers:

4
+7  A: 

Changing the look and feel of a program is as simple as :

UIManager.setLookAndFeel("fully qualified name of look and feel");

before any GUI creating code has been created. So you can easily create all your GUI with your GUI builder and the simply call this at the start of your program.

(Note that some look and feels like Substance are very strict when it comes to Threading issues so you better make sure that all your GUI code is run from the Event Dispatching Thread)

As a suggestion, two very good looking (and professional looking enough) look and feels in my opinion are Substance and also Nimbus which will ship with later releases of the JRE as the default lnf (at least that's the plan) and which can be downloaded separately from java.net

So if you opt for Nimbus the code would be :

UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");

And one example of Substance (Substance has many skins and themes, if you want to know more read their documentation in their site) would be :

UIManager.setLookAndFeel(new org.jvnet.substance.skin.SubstanceBusinessBlackSteelLookAndFeel());

Also note that you can use the cross platform skin (Metal) like this:

UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());

And finally if you are on windows you can use the system look and feel like this:

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
Savvas Dalkitsis
Note that UIManager.setLookAndFeel will throw a UnsupportedLookAndFeelException if it can't find said look and feel.
R. Bemrose
I needed to use UIManager .setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel") to get Nimbus to work. Note the com.sun.swing package, not javax.swing.
AngerClown
this is why you have a new jre version which includes the Nimbus look and feel in the "non official" com.sun packages. You cannot rely on this package being available in the future. The path i gave you "javax.swing" is correct if you download Nimbus as an external library. And also this will be the official name once Nimbus is included in the jre as the official package. So if i were you i'd download the library and use that until Nimbus ships as the default lnf.
Savvas Dalkitsis
Savvas, you said, "Also note that you can use the cross platform skin (Metal)...". Are all Substance skins not cross-platform? How can I tell which aren't?
ChrisC
no i meant the default cross platform look and feel that ships with Java. If you have code that allows the user to change the look and feel at runtime (via a menu for instance) then you will want to include the default look and feel in his options.To learn how to change the look and feel at runtime check out the answer R.Bemrose posted...
Savvas Dalkitsis
Thanks, Savvas!
ChrisC
A: 

Generally speaking, third-party GUI libraries with "look and feel" are not very popular, which is possibly an indication of their quality.

Standard GUI libraries are inherently very complex, and while they support some look and feel tweaking, the tweaks are often minor or constrained.

I would recommend sticking to Swing or SWT, and seeing what you can do with their look and feel mechanism, but don't expect miracles.

Uri
Why are they not very popular? Did you see the ones I linked to? They look pretty nice. What quality problems would deter people from using them?
ChrisC
+1  A: 

Building on what Uri said, you may want to stick with one of the more well-known look and feel.

If you use Swing, you may want to look into using the Nimbus look and feel... it's include with Java 6u10 and newer. Nimbus is built on the Synth framework included with Java 5 and newer.

Of course, if the end user is using a lower version, it will throw an UnsupportedLookAndFeelException and default to whatever the JVM default is (usually the Metal/Ocean (cross-platform) theme).

As a side note, if you use Swing, you can switch which look and feel is being used on the fly. You just have to call

// lnfName is the look and feel name
// frame is the window's JFrame
// try/catch block is omitted here
UIManager.setLookAndFeel(lnfName);
SwingUtilities.updateComponentTreeUI(frame);
frame.pack();
R. Bemrose
Could I not somehow include the necessary libraries (or whatever) with the installer so the user sees the look and feel I intended when I developed it?
ChrisC
you can include the look and feel .jar file in the distribution and also make it part of the class path. Then the users will be able to use it.
Savvas Dalkitsis
Is including the .jar files not common practice in the case of a non-standard look and feel design? Else why would R. Bemrose (or anyone else) be concerned about UnsupportedLookAndFeelException(s) and it defaulting to the default look and feel? Or do I not understand?
ChrisC
When you include the jar file in your distro you include it in a folder where you store your libraries (usually it is not mandatory). You program then invokes the library (in this case the look and feel). But what happens if the library is missing for some reason? You will get an apropriate exception in this case. There are some look and feels which are supported only on some platforms. For instance you cannot use some lnfs on windows and others on MacOS and others on Linux. This is when you get an UnsupportedLookAndFeelException.
Savvas Dalkitsis
+1  A: 

Ignoring the pro/con of choosing a LAF, I'll add some of my experience which using them...

If you're using a third-party/cots componentslibrary (JIDE, SwingLabs/SwingX, etc) you will have problems as UI classes won't always exist or be up to date with all of the LAFs. JIDE supports a few external LAFS (Alloy and Synthetica). Some LAFs also offer support for widgets, Substance supports some of JIDE and SwingX. The end result is an application that is partially skinned. Not pretty. Make sure your LAF supports all of you components. If you're pure Swing/AWT, no problems.

In light of this, we use Alloy for JIDE support, considering moving to Synthetica. Would love to use Substance, but no JIDE support.

basszero