Section 13.3. The Swing Component Set


[Page 607]

13.3. The Swing Component Set

Java's Swing components are defined in a collection of packages named javax.swing.*, which is imported by the code shown in this and subsequent chapters. Swing packages include the following:

javax.swing.event.* javax.swing.text.* javax.swing.plaf.* 


The javax.swing.event package defines the various Swing events and their listeners, such as the MenuEvent and the MenuListener. (In the AWT, the AWT events and listeners are defined in java.awt.event.)

The javax.swing.text package contains the classes for JTextField and JTextComponent. The Swing text components are more complex than their AWT counterparts. For example, one of their important features is the ability to undo changes made to the text they contain. This feature is crucial for building sophisticated word-processing applications.

The javax.swing.plaf package contains Swing's look-and-feel classes. The term plaf is an acronym for pluggable look and feel. It refers to the fact that changing an application's look and feel is a simple matter of "plugging in" a different plaf model. Changing how a program looks does not change what it does.

Look and feel


Swing's platform-independent look and feel is achieved by placing all the code responsible for drawing a component in a class that is separate from the component itself. For example, in addition to JButton, the class that defines the button control, there will be a separate class responsible for drawing the button on the screen. The drawing class will control the button's color, shape, and other characteristics of its appearance.

There are several look-and-feel packages built into Swing. For example, the javax.swing.plaf.motif package contains the classes that implement the Motif interface, a common Unix-based interface. The javax.swing.plaf.windows packages contains classes that support a Windows look and feel, and the javax.swing.plaf.metal package provides classes that support the Metal interface, a Java look and feel. These classes know how to draw each component and how to react to mouse, keyboard, and other events associated with these components.




Java, Java, Java(c) Object-Orienting Problem Solving
Java, Java, Java, Object-Oriented Problem Solving (3rd Edition)
ISBN: 0131474340
EAN: 2147483647
Year: 2005
Pages: 275

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net