Java Reference
In-Depth Information
looking at the full picture
You've now seen the differences between Swing components and containers and already utilized a
handful of Swing classes. Earlier, you read that Swing extends the older and native AWT library. It
therefore makes sense to take a step back and look at the whole class hierarchy to understand what
exactly is going on, as the GUI hierarchy in Java can be somewhat confusing.
Start with the class tree representing only AWT objects, which will keep Swing out of the mix for
now. You then end up with the GUI class hierarchy illustrated in Figure 11-4.
java.lang. Object
java.awt. Component
Other AWT
Components
java.awt.Label
java.awt.Checkbox
java.awt.Button
java.awt. Container
Other AWT
Components
java.awt.Panel
java.awt.Window
java.awt.Applet
java.awt.Frame
java.awt.Dialog
figure 11-4  
However, recall that you have been using J‐classes ( JButton , JFrame , and JWindow ), that is, Swing
classes. This means completely ignoring the AWT components and containers when making GUIs.
Now see what happens when you ignore the AWT components and add the Swing components to the
mix. This is illustrated in Figure 11-5.
java.lang. Object
java.awt. Component
AWT Components
java.awt. Container
AWT Containers
javax.swing. JComponent
Other Swing
Components
javax.swing.JPanel
javax.swing.JLabel
figure 11-5  
Note that each Swing component extends the JComponent , and that JComponent itself extends the AWT
Container class, meaning that a JButton does not extend an AWT Button, a JLabel does not extend
an AWT Label, and so on.
Now, where do Swing containers fit in? One of them, the JPanel , you can already find among the
JComponents . However, the ones with a window border, namely JFrame , JApplet , JDialog , and
JWindow , are missing. They are added to the class tree as shown in Figure 11-6.
 
 
Search WWH ::




Custom Search