|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object![]()
![]()
![]()
java.awt.Component
![]()
![]()
![]()
java.awt.Container
![]()
![]()
![]()
javax.swing.JComponent
![]()
![]()
![]()
javax.swing.JRootPane
, MenuContainer
, Serializable
, Accessible

public class JRootPane


A lightweight container used behind the scenes by
JFrame, JDialog, JWindow,
JApplet, and JInternalFrame.
For task-oriented information on functionality provided by root panes
see How to Use Root Panes,
a section in The Java Tutorial.
The following image shows the relationships between the classes that use root panes.

JFrame, JDialog,
JWindow, and JApplet) are
shown in relation to the AWT classes they extend.
These four components are the
only heavyweight containers in the Swing library. The lightweight container
JInternalPane is also shown.
All five of these JFC/Swing containers implement the
RootPaneContainer interface,
and they all delegate their operations to a
JRootPane (shown with a little "handle" on top).
Note: TheJComponentmethodgetRootPanecan be used to obtain theJRootPanethat contains a given component.
|
JRootPane.
A JRootpane is made up of a glassPane,
an optional menuBar, and a contentPane.
(The JLayeredPane manages the menuBar
and the contentPane.)
The glassPane sits over the top of everything,
where it is in a position to intercept mouse movements.
Since the glassPane (like the contentPane)
can be an arbitrary component, it is also possible to set up the
glassPane for drawing. Lines and images on the
glassPane can then range
over the frames underneath without being limited by their boundaries.
Although the menuBar component is optional,
the layeredPane, contentPane,
and glassPane always exist.
Attempting to set them to null generates an exception.
To add components to the JRootPane (other than the
optional menu bar), you add the object to the contentPane
of the JRootPane, like this:
rootPane.getContentPane().add(child);
The same principle holds true for setting layout managers, removing
components, listing children, etc. All these methods are invoked on
the contentPane instead of on the JRootPane.
Note: The default layout manager for theIf acontentPaneis aBorderLayoutmanager. However, theJRootPaneuses a customLayoutManager. So, when you want to change the layout manager for the components you added to aJRootPane, be sure to use code like this:rootPane.getContentPane().setLayout(new BoxLayout());
JMenuBar component is set on the JRootPane,
it is positioned along the upper edge of the frame.
The contentPane is adjusted in location and size to
fill the remaining area.
(The JMenuBar and the contentPane are added to the
layeredPane component at the
JLayeredPane.FRAME_CONTENT_LAYER layer.)
The layeredPane is the parent of all children in the
JRootPane -- both as the direct parent of the menu and
the grandparent of all components added to the contentPane.
It is an instance of JLayeredPane,
which provides the ability to add components at several layers.
This capability is very useful when working with menu popups,
dialog boxes, and dragging -- situations in which you need to place
a component on top of all other components in the pane.
The glassPane sits on top of all other components in the
JRootPane.
That provides a convenient place to draw above all other components,
and makes it possible to intercept mouse events,
which is useful both for dragging and for drawing.
Developers can use setVisible on the glassPane
to control when the glassPane displays over the other children.
By default the glassPane is not visible.
The custom LayoutManager used by JRootPane
ensures that:
glassPane fills the entire viewable
area of the JRootPane (bounds - insets).
layeredPane fills the entire viewable area of the
JRootPane. (bounds - insets)
menuBar is positioned at the upper edge of the
layeredPane.
contentPane fills the entire viewable area,
minus the menuBar, if present.
JRootPane view hierarchy are ignored.
If you replace the LayoutManager of the JRootPane,
you are responsible for managing all of these views.
So ordinarily you will want to be sure that you
change the layout manager for the contentPane rather than
for the JRootPane itself!
The painting architecture of Swing requires an opaque
JComponent
to exist in the containment hieararchy above all other components. This is
typically provided by way of the content pane. If you replace the content
pane, it is recommended that you make the content pane opaque
by way of setOpaque(true). Additionally, if the content pane
overrides paintComponent, it
will need to completely fill in the background in an opaque color in
paintComponent.
Warning:
Serialized objects of this class will not be compatible with
future Swing releases. The current serialization support is
appropriate for short term storage or RMI between applications running
the same version of Swing. As of 1.4, support for long term storage
of all JavaBeansTM
has been added to the java.beans package.
Please see XMLEncoder
.
JLayeredPane
,
JMenuBar
,
JWindow
,
JFrame
,
JDialog
,
JApplet
,
JInternalFrame
,
JComponent
,
BoxLayout
,
Mixing Heavy and Light Components,
Serialized Form| Nested Class Summary | |
|---|---|
protected class |
JRootPane.AccessibleJRootPane
This class implements accessibility support for the JRootPane class. |
protected class |
JRootPane.RootLayout
A custom layout manager that is responsible for the layout of layeredPane, glassPane, and menuBar. |
Nested classes/interfaces inherited from class javax.swing.JComponent ![]() |
|---|
JComponent.AccessibleJComponent |
Nested classes/interfaces inherited from class java.awt.Container ![]() |
|---|
Container.AccessibleAWTContainer |
Nested classes/interfaces inherited from class java.awt.Component ![]() |
|---|
Component.AccessibleAWTComponent |
| Field Summary | |
|---|---|
static int |
COLOR_CHOOSER_DIALOG
Constant used for the windowDecorationStyle property. |
protected Container |
contentPane
The content pane. |
protected JButton |
defaultButton
The button that gets activated when the pane has the focus and a UI-specific action like pressing the Enter key occurs. |
protected javax.swing.JRootPane.DefaultAction |
defaultPressAction
Deprecated. As of Java 2 platform v1.3. |
protected javax.swing.JRootPane.DefaultAction |
defaultReleaseAction
Deprecated. As of Java 2 platform v1.3. |
static int |
ERROR_DIALOG
Constant used for the windowDecorationStyle property. |
static int |
FILE_CHOOSER_DIALOG
Constant used for the windowDecorationStyle property. |
static int |
FRAME
Constant used for the windowDecorationStyle property. |
protected Component |
glassPane
The glass pane that overlays the menu bar and content pane, so it can intercept mouse movements and such. |
static int |
INFORMATION_DIALOG
Constant used for the windowDecorationStyle property. |
protected JLayeredPane |
layeredPane
The layered pane that manages the menu bar and content pane. |
protected JMenuBar |
menuBar
The menu bar. |
static int |
NONE
Constant used for the windowDecorationStyle property. |
static int |
PLAIN_DIALOG
Constant used for the windowDecorationStyle property. |
static int |
QUESTION_DIALOG
Constant used for the windowDecorationStyle property. |
static int |
WARNING_DIALOG
Constant used for the windowDecorationStyle property. |
Fields inherited from class javax.swing.JComponent ![]() |
|---|
accessibleContext |
Fields inherited from class java.awt.Component ![]() |
|---|
BOTTOM_ALIGNMENT |
Fields inherited from interface java.awt.image.ImageObserver ![]() |
|---|
ABORT |
| Constructor Summary | |
|---|---|
JRootPane
Creates a JRootPane, setting up its
glassPane, layeredPane,
and contentPane. |
|
| Method Summary | |
|---|---|
protected void |
addImpl
Overridden to enforce the position of the glass component as the zero child. |
void |
addNotify
Register ourselves with the SystemEventQueueUtils as a new
root pane. |
protected Container |
createContentPane
Called by the constructor methods to create the default contentPane. |
protected Component |
createGlassPane
Called by the constructor methods to create the default glassPane. |
protected JLayeredPane |
createLayeredPane
Called by the constructor methods to create the default layeredPane. |
protected LayoutManager |
createRootLayout
Called by the constructor methods to create the default layoutManager. |
AccessibleContext |
getAccessibleContext
Gets the AccessibleContext associated with this
JRootPane. |
Container |
getContentPane
Returns the content pane -- the container that holds the components parented by the root pane. |
JButton |
getDefaultButton
Returns the value of the defaultButton property. |
Component |
getGlassPane
Returns the current glass pane for this JRootPane. |
JMenuBar |
getJMenuBar
Returns the menu bar from the layered pane. |
JLayeredPane |
getLayeredPane
Gets the layered pane used by the root pane. |
JMenuBar |
getMenuBar
Deprecated. As of Swing version 1.0.3 replaced by getJMenubar(). |
RootPaneUI |
getUI
Returns the L&F object that renders this component. |
String |
getUIClassID
Returns a string that specifies the name of the L&F class that renders this component. |
int |
getWindowDecorationStyle
Returns a constant identifying the type of Window decorations the JRootPane is providing. |
boolean |
isOptimizedDrawingEnabled
The glassPane and contentPane
have the same bounds, which means JRootPane
does not tiles its children and this should return false. |
boolean |
isValidateRoot
If a descendant of this JRootPane calls
revalidate, validate from here on down. |
protected String |
paramString
Returns a string representation of this JRootPane. |
void |
removeNotify
Unregister ourselves from SystemEventQueueUtils. |
void |
setContentPane
Sets the content pane -- the container that holds the components parented by the root pane. |
void |
setDefaultButton
Sets the defaultButton property,
which determines the current default button for this JRootPane. |
void |
setGlassPane
Sets a specified Component to be the glass pane for this
root pane. |
void |
setJMenuBar
Adds or changes the menu bar used in the layered pane. |
void |
setLayeredPane
Sets the layered pane for the root pane. |
void |
setMenuBar
Deprecated. As of Swing version 1.0.3 replaced by setJMenuBar(JMenuBar menu). |
void |
setUI
Sets the L&F object that renders this component. |
void |
setWindowDecorationStyle
Sets the type of Window decorations (such as borders, widgets for closing a Window, title ...) the JRootPane should
provide. |
void |
updateUI
Resets the UI property to a value from the current look and feel. |
Methods inherited from class javax.swing.JComponent ![]() |
|---|
addAncestorListener |