Graphic Java 2: Mastering the Jfc, By Geary, 3Rd Edition, Volume 2: Swing
Here is a short description of each package in the Swing libraries:
By far the most widely used package is javax.swing. In fact, almost all the Swing components, as well as several utility classes, are located inside this package. The only exceptions are borders and support classes for the trees, tables, and text-based components. Because the latter components are much more extensible and often have many more classes to work with, these classes have been divided into separate packages. 1.3.1 Class Hierarchy
Figure 1-5 shows a detailed overview of the Swing class hierarchy as it appears in the 1.4 SDK. At first glance, the class hierarchy looks very similar to AWT. Each Swing component with an AWT equivalent shares the same name, except that the Swing class is preceded by a capital J. In most cases, if a Swing component supersedes an AWT component, it can be used as a drop-in replacement. Figure 1-5. The Swing component hierarchy Upon closer inspection, however, you will discover that there are welcome differences between the Swing and AWT components. For example, the menu components, including JMenuBar, are now descendants of the same base component as the others: JComponent. This is a change from the older AWT menu classes. Both the AWT 1.0 and 1.1 menu classes inherited their own high-level component, MenuComponent, which severely limited their capabilities. In addition, this design prevented menu bars from being positioned with layout managers inside containers; instead, Java simply attached menu bars to the top of frames. Also, note that Swing has redesigned the button hierarchy. It now includes a JToggleButton class, used in dual-state components. For example, if you click on a toggle button while in the released position, the button switches to the pressed state and remains in that state. When it is clicked again, the button returns to the released state. Note that JToggleButton outlines behavior seen in radio buttons and checkboxes. Hence, these classes inherit from JToggleButton in the new Swing design. Also note the addition of the JRadioButton and JRadioButtonMenuItem classes in Swing. Until now, Java forced developers to use the AWT checkbox equivalent to mimic radio buttons. You might have noticed an increase in the number of frames and panes in Swing. For example, consider internal frames. Swing supports placing frames inside other frames this is commonly referred to as a multiple document interface (MDI) in the Microsoft Windows world. You can assign these internal frames arbitrary vertical layers; these layers determine which internal frame appears on top. In fact, even the simplest frame, JFrame, embraces the concept of layers by including support for layered panes on which you can position different elements of your application. These topics are discussed in more detail in Chapter 9 and Chapter 11. There are many other design enhancements in Swing too many, in fact, to discuss here. However, before we go on, we should discuss one of the fundamental designs behind every Swing component: the model-view-controller architecture. |