Java Swing
Java Swing
Java Swing
Why couldn't all the enhancements and new components simply be added to AWT?
Each AWT component gets its own operating platform window. In extended programs, a large number of such windows slows performance uses up a great deal of memory. Such components are called heavyweight components. Swing controls, on the other hand, are simply drawn as images in their containers and dont have a platform window of their own at all, so they use fewer system resources. Therefore, they are called lightweight components. However not all swing components are lightweight. To display anything in a windowed environment, some operating system windows are needed, if only in which to draw lightweight controls. For this reason, Swing supports these heavyweight classes: JFrame, JDialog, JWindow & JApplet
In addition to this, the root pane (shown in figure below) is virtual container that contains the content pane, the layered pane, the glass pane and the menu bar
Frame Content Layer Menu bar Layered Pane
Content Pane
Glass Pane
Content Pane
Content Pane actually sits on one of the layers of the layered pane. A layered pane contains several layers meant for displaying Swing components, depending on their overlapping requirements. The menu Bar and the content pane sit on the Frame_Content_Layer
Content Pane
Glass Pane
Glass Pane
The glass pane is a member of the root pane that is used to draw over an area that already contains some components. A glass pane can also be used to catch mouse events because it sits over the top of the content pane and menu bar.
Because glass pane is a member of the root pane, it already exists in a Swing container.
However the glass pane is not visible by default.
Menu Bars
The menu bars are added to the menu bar area, which is a thin rectangular area along the upper edge of the frame content pane layer of the layered pane. The remaining area of the thin layer is filled with the content pane.
To obtain a reference to the optional menu bar that exists with a Swing frame, the method getMenuBar() on the container object can be called.
Layered Pane
A layered pane object is represented by the Swing class JLayeredPane, which extends JComponent. The class is stored in the package javax.swing For convenience, JlayeredPane divides the depth range into several different layers. Putting a component into one of these layers ensures that components overlap properly.
DEFAULT_LAYER: The standard, bottommost layer, where most components go. PALETTE_LAYER: The palette layer sits over the default layer and is useful for
floating toolbars and palettes.
MODAL_LAYER: The layer used for modal dialog boxes. POPUP_LAYER: The pop-up layer displays above the dialog area. DRAG_LAYER: When a component is dragged, assigning it to a drag layer makes
sure its positioned over all the other components in the container.