Java Sun and JLF home page   Previous Next Contents/Index/Search

2: The Java Foundation Classes

This book assumes that you are designing software based on the Java Foundation Classes and utilizing the Java look and feel. This chapter provides an overview of that technology: the Java Development Kit and Java TM 2 SDK, the user interface components of the Java Foundation Classes, the pluggable look and feel architecture, and available look and feel designs.

 

 

Java Development Kit

The APIs and tools that developers need to write, compile, debug, and run Java applications are included in the Java Development Kit (JDK TM) and Java 2 SDK .

The guidelines in this book pertain to applications built with the Java 2 SDK, Standard Edition, v. 1.2 (referred to hereafter as "Java 2 SDK"), or the Java Development Kit versions 1.1.3 through 1.1.7 (referred to hereafter as "JDK 1.1"). The Java Foundation Classes are available for use with JDK 1.1, but they are an integral part of the Java 2 platform.

 
Java Foundation Classes

The Java Foundation Classes (JFC) include the Swing classes , which define a complete set of graphic interface components for JFC applications. An extension to the original Abstract Window Toolkit, the JFC includes the Swing classes, pluggable look and feel designs, and the Java Accessibility API, which are all implemented without native code (code that refers to the methods of a specific operating system or is compiled for a specific processor). The JFC components include windows and frames, panels and panes, dialog boxes, menus and toolbars, buttons, sliders, combo boxes, text components, tables, lists, and trees.

All the components have look and feel designs that you can specify. The cross-platform, default look and feel is the Java look and feel . For details on the design principles and visual elements underlying the Java look and feel, see Chapter 1.

 In code, the Java look and feel is referred to as "Metal."

 
JDK 1.1 and the Java 2 SDK

The following figure summarizes the differences in the Java Foundation Classes in JDK 1.1 and the Java 2 SDK. Both development kits contain the Abstract Window Toolkit (AWT), the class library that provides the standard application programming interfaces for building graphical user interfaces for Java programs. There is native code in the AWT code in both kits, and in drag and drop and the Java 2D TM API in the Java 2 SDK.

 

Figure 14 Java Foundation Classes for JDK 1.1 and the Java 2 SDK

In the Java 2 SDK, the Java Foundation Classes also include the Java 2D API, drag and drop, and other enhancements. The Java 2D API provides an advanced two-dimensional imaging model for complex shapes, text, and images. Features include enhanced font and color support and a single, comprehensive rendering model.

 
Support for Accessibility

Three features of JDK 1.1 and the Java 2 SDK support people with special needs: the Java Accessibility API, the pluggable look and feel architecture, and keyboard navigation.

The Java Accessibility API provides ways for an assistive technology to interact and communicate with JFC components. A Java application that fully supports the Java Accessibility API is compatible with technologies such as screen readers and screen magnifiers. A separate package, Java Accessibility Utilities , provides support in locating the objects that implement the Java Accessibility API.

A pluggable look and feel architecture is used to build both visual and nonvisual designs, such as audio and tactile user interfaces. For more on the pluggable look and feel, see Pluggable Look and Feel Architecture.

Keyboard navigation enables users to move between components, open menus, highlight text, and so on. This support makes an application accessible to people who do not use a mouse. For details on keyboard operations, see Appendix A.

 
Support for Internationalization

JDK 1.1 and the Java 2 SDK provide internationalized text handling. This feature includes support for the bidirectional display of text lines--important for displaying documents that mix languages with a left-to-right text direction (for instance, English, German, or Japanese) and languages with a right-to-left direction (for instance, Arabic or Hebrew). JDK 1.1 and the Java 2 SDK also provide resource bundles, locale-sensitive sorting, and support for localized numbers, dates, times, and messages.

 

 

User Interface Components of the Java Foundation Classes

The Java Foundation Classes include Swing, a complete set of user interface components, including windows, dialog boxes, alert boxes, panels and panes, and basic controls. Each JFC component contains a model (the data structure) and a user interface (the presentation and behavior of the component), as shown in the following illustration.

 

Figure 15 Structure of the JFC Components

 
Pluggable Look and Feel Architecture

Because both presentation and behavior are separate and replaceable ("pluggable"), you can specify any of several look and feel designs for your application--or you can create your own look and feel. The separation of a component's model (data structure) from its user interface (display and interaction behavior) is the empowering principle behind the pluggable look and feel architecture of the JFC. A single JFC application can present a Java look and feel, a platform-specific look and feel, or a customized interface (for example, an audio interface).

 
Example Model and Interface

Consider the slider in the following figure as a simplified example. The slider's model contains information about the slider's current value, the minimum and maximum values, and other properties. The slider's user interface determines how users see or interact with the slider. The model knows almost nothing about the user interface--while the user interface knows a great deal about the model.

 

Figure 16 Pluggable Look and Feel Architecture of a Slider

 
Client Properties

You can use the client properties mechanism to display an alternate form of a specific Java user interface component. If a look and feel design does not support the property, it ignores the property and displays the component as usual. You can set alternate appearances for sliders, toolbars, trees, and internal frames. For instance, a nonfilling slider is displayed by default. However, by using the client properties mechanism, you can display a filling slider, as shown in Figure 16.

 
Major JFC User Interface Components

The following table illustrates the major user interface components in the JFC. Components are listed alphabetically by their names in code. Their English names are provided, followed by the location of more detailed information on each component.

Table  1 Names and Appearance of the JFC User Interface Components 
Component Code Name Common Name For Details
 JApplet Applet Click here
 JButton Command button and toolbar button Click here
Click here
 JCheckBox Checkbox Click here
 JCheckBoxMenuItem Checkbox menu item Click here
 JColorChooser Color chooser Click here
 JComboBox Noneditable and editable combo boxes Click here
 JDesktopPane Desktop pane Click here
 JDialog Dialog box, secondary window, and utility window Click here
Click here
Click here
 JEditorPane Editor pane Click here
 JFrame Primary window Click here
 JInternalFrame Internal frame, minimized internal frame, and palette window Click here
Click here
Click here
 JLabel Label Click here
 JList List Click here
 JMenu Drop-down menu and submenu Click here
Click here
 JMenuBar Menu bar Click here
 JMenuItem Menu item Click here
 JOptionPane Alert box Click here
 JPanel Panel Click here
 JPasswordField Password field Click here
 JPopupMenu Contextual menu Click here
 JProgressBar Progress bar Click here
 JRadioButton Radio button Click here
 JRadioButtonMenuItem Radio button menu item Click here
 JScrollBar Scrollbar Click here
 JScrollPane Scroll pane Click here
 JSeparator Separator Click here
 JSlider Slider Click here
 JSplitPane Split pane Click here
 JTabbedPane Tabbed pane Click here
 JTable Table Click here
 JTextArea Plain text area Click here
 JTextField Noneditable and editable text fields (single line) Click here
 JTextPane Editor pane with the styled editor kit plug-in Click here
 JToggleButton Toggle button and toolbar button Click here
Click here
 JToolBar Toolbar Click here
 JToolTip Tool tip Click here
 JTree Tree view Click here
 JWindow Plain (unadorned) window Click here
 

 

 In the JFC, the typical primary windows that users work with are based on the JFrame component. Unadorned windows that consist of a rectangular region without any title bar, close control, or other window controls are based on the JWindow component. Designers and developers typically use the JWindow component to create windows without title bars, such as splash screens.

For details on the use of windows, frames, panels, and panes, see Chapter 7.

 

 

Look and Feel Options

You, the designer, have the first choice of a look and feel design. You can determine the look and feel you want users to receive on a specific platform, or you can choose a cross-platform look and feel.

 
Java Look and Feel--the Recommended Design

With a cross-platform look and feel, your application will appear and perform the same everywhere, simplifying the application's development and documentation.

 Specify the Java look and feel, which is a cross-platform look and feel, explicitly. If you do not specify a look and feel or if an error occurs while specifying the name of a look and feel, the Java look and feel is used by default.

 The following code can be used to specify the Java look and feel explicitly:
UIManager.setLookAndFeel(
UIManager.getCrossPlatformLookAndFeelClassName() );

 
Alternative Approaches

If you do not specify the Java look and feel, you can specify:

 

  • A particular look and feel--one that ships with the JFC or one that someone else has made. Note, however, that not all look and feel designs are available on every platform. For example, the Microsoft Windows look and feel is available only on the Microsoft Windows platform.
  • An auxiliary look and feel--one that is designed to be used in addition to the primary look and feel. By combining look and feel designs, you can target different ways of perceiving information.

Because there is far more to the design of an application than the look and feel of components, it is unwise to give end users the ability to swap look and feel designs while working in your application. Switching look and feel designs in this way only swaps the look and feel designs of the components from one platform to another. The layout and vocabulary used are platform- specific and do not change. For instance, swapping look and feel designs does not change the titles of the menus.

 Make it possible for your users to specify an auxiliary look and feel design, which provides alternative methods of information input and output for people with special needs.

 
Supplied Designs

The look and feel designs available in JDK 1.1 and the Java 2 SDK are:

 

  • Java look and feel. (Called "Metal" in the code.) The Java look and feel is designed for use on any platform that supports the JFC. This book provides recommendations on the use of the Java look and feel.
  • Microsoft Windows. (Called "Windows" in the code.) The Microsoft Windows style look and feel can be used only on Microsoft Windows platforms. It follows the behavior of the components in applications that ship with Windows NT 4.0. For details, see Windows Interface Guidelines for Software Design.
  • CDE. (Called "CDE/Motif" in the code.) The CDE style look and feel is designed for use on UNIX ® platforms. It emulates OSF/Motif 1.2.5, which ships with the Solaris TM 2.6 operating system. It can run on any platform. For details, see the CDE 2.1/Motif 2.1--Style Guide and Glossary.

In addition, you can download the Macintosh style look and feel (called "Mac OS" in the code) separately. The Macintosh style look and feel can be used only on Macintosh operating systems. It follows the specification for components under Mac OS 8.1. For details, see the Mac OS 8 Human Interface Guidelines.




 

Java homepage  :  Design Guidelines Previous  |  Next  |  Contents  |  Index  |  Search

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved.

Left Curve
Java SDKs and Tools
Right Curve
Left Curve
Java Resources
Right Curve
JavaOne Banner
Java 8 banner (182)