Java Reference
In-Depth Information
Window Panes
When you want to add GUI components or draw in a window displayed from a JFrame object, you
add the components to, or draw on, a window pane that is managed by the JFrame object. The same
goes for an applet. Broadly speaking, window panes are container objects that represent an area of a
window, and they come in several different types.
You will use a
window pane called
the content pane
most of the time, but
there are others. The
relationship between
the contentPane
object, other window
panes, and the
application window
itself is shown here.
JFrame Window
The area of the window below the title bar
corresponds to a JRootPane Object
LayeredPane object of type JLayeredPane
contentPane object of type JInternalPane
The contentPane is where you normally add components
other than a menubar to a window. A reference to
contentPane is returned by the getContentPane() member
of the JFrame object
As you see, the area below the title bar in a JFrame window corresponds to a JRootPane object. This
contains another pane, the layeredPane object in the illustration, which is of type JLayeredPane .
This pane corresponds to the whole of the area occupied by the JRootPane object in the window and
manages the menu bar if the window has one. The area in the layeredPane below the menu bar
corresponds to the contentPane object, and it's here that you typically add GUI components. You
also display text or do any drawing in the area covered by the content pane.
The layeredPane object has special properties for advanced applications that permit groups of
components to be managed in separate layers that overlay one another within the pane. With this
capability you can control how components are displayed relative to one another, because the layers are
displayed in a particular order from back to front. The components in a layer at the front will appear on
the screen in front of those in a layer that is towards the back.
There is also an additional pane not shown in the diagram. This is the glassPane object, and this also
corresponds to the complete JRootPane area. The contents of the glassPane object displays on top
of all the other panes, so this is used to display components that you always want to display on top of
anything else displayed in the window - such as pop-up menus. You can also use the glassPane to
display graphics that need to be updated relatively frequently - such as when you create an animation.
When part of what is displayed is to be animated, a static background can be displayed independently
via the contentPane . Since this doesn't need to be reprocessed each time the animated objects need
to be redrawn, the whole process can be much more efficient.
The JFrame class defines methods to provide you with a reference to any of the panes:
Search WWH ::




Custom Search