January 20, 2005

Java Look n Feel Design

Vikram Mohan writes " As the Java platform has undergone development, developers have felt the need for programs that are uniform in looks and development of user friendly Java applications.

The Java look and feel completes that criteria by giving means for making platform-independent programs that are similar in behaviour and appearance. The use of this single look and feel reduces designing and actual time spent for coding and cuts down costs on training as the same code can be used to give different appearences by merely making use of another Look and Feel manager.

The Java look and feel is the default interface for applications built with the Java Foundation Classes.

The Java look and gives the ability to have

        * Consistency in the appearance and behavior of common design elements
        * Compatibility with industry-standard components and interaction styles
        * Aesthetic appeal that does not distract from application content

A designer gets the ultimate call in designing a Look and Feel he may either choose a corresponding one for a particular Operating System or choose one that is compatible cross platform.

When a cross-platform look and feel is chosen the application looks the same whatever environment it is deployed in making documentation a simpler task as the same guidelines can be followed uniformly.

Enabling dynamic switching of look and feel within an application might be considered by some as a feature that might enhance user friendliness and beauty and an umpteen number of additional reasons however an application is defined by various factors other than its look and feel. Switching look and feel designs in this manner only allows changing the look and feel designs of the components from one platform to another. A considerate and noteable feature worth implementing would be use of a design approach that is auxillary such as allowing multiple methods for input for a physically challenged person. Changing look and feel is meant as a design tool, not as a runtime tool

In order to understand how to make a pluggable ( similar to a plugin approach ) look and feel package, the look and feel developer must, first, understand how Java accomplishes look and feel for Swing components.

Java separates Swing into two set of classes: lightweight and heavyweight. The heavyweight classes delegate painting to the operating system with some user input depending on how much control the operating system assigns the user. The other classes are the Swing lightweight classes which all inherit from the main component class ( JComponent ) and hand over the painting tasks to a separate User Interface class.

When a lightweight Swing class is instantiated, it calls the User Interface Manager ( UIManager ) to retrieve the User Interface class that is responsible for painting that class to the output device which it gets details from the User Interface Defaults class. The User Interface Manager gets the User Interface Defaults ( UIDefaults ) class from the LookAndFeel class that is set by the corresponding method. Once the basic concepts have been grasped development in this field is only a minor issue.

The theme mechanism can be used to manipluate attribute's of the Java look and feel design. It enables you to specify different colors and fonts across an entire Java look and feel application and might find application in implimentation specific features such as visually distinguishing consolses of user's logged in with different access priviliges.

When modifying theme colours extreme caution has to be taken to keep the visual elements coherent. interface elements remain visually coherent. The Java look and feel uses a simple color model so that it can run on a variety of platforms and on devices capable of displaying various depths of color.A total of eight colours are defined for each platform:-

        * Three primary colors to give the theme a color identity and to emphasize selected items
        * Three secondary colors, typically shades of gray, for neutral drawing and inactive or disabled items
        * Two additional colors, usually defined as black and white, for the display of text and highlighting

Within the primary and secondary color groups in the default theme, there is a gradation from dark (primary 1 and secondary 1) to lighter (primary 2 and secondary 2) to lightest (primary 3 and secondary 3).

To ensure consistency and user friendliness the default fonts should be made use of unless there is sufficient reason to do so for an application-wide change (such as readability). The theme mechanism should be made use of to make such changes.

Font sizes should not be hard coded into themes and source code but font sizes and styles should be stored in resource bundles and the use of a LayoutManager should be made use of to ensure the application can handle different font sizes. " All fonts in the Java look and feel are defined in the default Java look and feel theme as Dialog, which maps to a platform-specific font. "

There are two design methods of creating a look and feel in Java. One is to by extending the pluggable look and feel ( javax.swing.plaf ) package and the other is to extend an existing look and feel package ( usually javax.swing.plaf.basic ).

Extending a look and feel from the look and feel manager package ( javax.swing.plaf ) is not recommended if the deployment target is a personal computer. This is because the Swing look and feel basic ( javax.swing.plaf.basic ) package has extended almost the entirety of the look and feel ( javax.swing.plaf ) package for the developer to use. This allows the look and feel developer to pick and choose which things about the look and feel to customize without having to implement everything and focus on crucial tasks. However if output is designed for an output device other than a computer screen extending the look and feel classes ( javax.swing.plaf ) from scratch is feasible."

Link: vikram.blogspot.com


  • Java
Click Here!