Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Spring Framework | Web Services | BioInformatics | Java Server Faces | Jboss 3.0 tutorial | Hibernate 3.0 | XML

Tutorial Categories: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML


 

Java Tutorials


 

 

Struts Tutorials

Struts Resources

Visit Forum! Post Questions!
Jobs At RoseIndia.net!

Java Notes

Look and Feel

For best portability use the default Java cross-platform Look & Feel. There are several good reasons to change it however.

  • Avoid ugliness. Before Java 5, the default L&F, Metal, was relatively unattractive.
  • System L&F. It's nice to match the system L&F, eg, on Windows the program should have a Windows L&F, on the Macintosh it should use the standard Macintosh L&F..
  • Special. You would like some special appearance.

The javax.swing.UIManager class methods can be used to set it.

To Set the Look and Feel

try {
    UIManager.setLookAndFeel(XXX);
} catch (Exception e) {
    // This is one of the few places where silently ignoring an exception
    // might be the right thing to do, altho it is almost always
    // a very bad practice.  What else can we do in this case?
    // The default look & feel will be used if we ignore this.
}

Where XXX is one of the following:

The Java cross-platform L&F
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
The current OS L&F
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
Windows L&F
"com.sun.java.swing.plaf.windows.WindowsLookAndFeel" can currently only be used on Windows.
Macintosh L&F
"javax.swing.plaf.mac.MacLookAndFeel" can currently only be used on the Macintosh [still true?]. Note: The look and feel code doesn't move menu elements around to match the the relevant system.
CDE/Motif Look and Feel
"com.sun.java.swing.plaf.motif.MotifLookAndFeel" can be used on any system.

Custom Look and Feel

A number of custom Looks and Feels have been developed. Take a look at www.javootoo.com for examples and links to some. A nice L&F for informal appearance is Napkin, at napkinlaf.sourceforge.net/.

You can easily install these: just put the .jar file in the CLASSPATH, and make the appropriate call as above. For example, to use the Kunststoff L&F, add the .jar file to your classpath and make the following call.

UIManager.setLookAndFeel(new com.incors.plaf.kunststoff.KunststoffLookAndFeel());

Dynamically updated Look & Feel

Most programs don't change the L&F, and those that do will set the L&F at the beginning, before any GUI elments have been created. If you want to dynamically change the L&F, you must call updateComponentTreeUI(), passing it the component, typically your window, that must be updated to the new Look & Feel.

UIManager.setLookAndFeel(...);
SwingUtilities.updateComponentTreeUI(myWindow);

Java 5 skinnable Synth Look&Feel

Java 5 introduced the Synth L&F, which can be customized by changing an XML text file, making it relatively easy to customize a L&F. Take a look at the following.

Ask programming questions?

 

 

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

0 comments so far (post your own) View All Comments Latest 10 Comments:
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification

Tell A Friend
Your Friend Name

 

 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright 2007. All rights reserved.

[an error occurred while processing this directive]