Differences between AWT and Swing
1. Unlike AWT components, Swing components carries information along with it and hence will not contact the OS. This increases the performance of the application.
2. Swing components are lightweight components and where as AWT components are heavyweight components.
3. The extra features of Swing which do not exist in AWT are, for example, it is possible to display images on button, setting a tool-tip for a button and specifying an access key (or hotkey or shortcut key) for a button.
4. Lightweight components need not be rectangular while heavyweight components are always rectangular.
5. AWT can make use of both 1.0 and 1.1 event handling. But JFC components will work with 1.1 event handling.
Swing Introduction: Main New Features
1. Lightweight: Not built on native window-system windows.
2. Much bigger set of built-in controls: Trees, image buttons, tabbed panes, sliders, toolbars, color choosers, tables, text areas to display HTML or RTF(Rich Text Format) etc.
3. Much more customizable: Can change border, text alignment, or add image to almost any control. Can customize how minor features are drawn. Can separate internal representation from visual appearance.
4. "Pluggable" look and feel: Can change look and feel at runtime, or design own look and feel.
5. Many miscellaneous new features: Double-buffering built in, tool tips, dockable tool bars, keyboard accelerators, custom cursors, etc
6. Model-View-Controller architecture: It lets us change the internal data representation for lists, trees, tables, etc.
7. Metallic look: We get Java Metal look by default and we can change to the native look when ever wanted.
For more features visit on Swing Introduction: Swing Overview
The supporting packages for swing components are javax.swing and javax.swing.event.
Content pane: The content pane is associated with JFrame. The content pane is the container that contains the components. The content pane resides on JFrame. Components should be added to a JFrame through content pane and not directly to the JFrame itself (in AWT, we add components to frame itself). getContentPane() method of JFrame returns an object of Container class as follows :
Container c = getContentPane() ;
The default layout manager is BorderLayout.
Following is the method signature of the getContentPane() method:
public Container getContentPane()
That is, we add swing components to the Container returned by the getContentPane() method of JFrame. In turn, Container adds to JFame (as container resides on JFrame, the components look as if added to JFrame). The default layout manager for Container is BorderLayout.
Why all this content pane or container?