JFrame, JDialog, JWindow,
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, and
JWindow) are shown in relation to the AWT classes they extend.
These three components are the only heavyweight containers in the Swing library.
The lightweight container JInternalFrame is also shown in green with thin outline.
All four of these JFC/Swing containers implement the RootPaneContainer interface,
and they all delegate their operations to a JRootPane.Note
The JComponent method getRootPane
can be used to obtain the JRootPane that contains
a given component.
Example:
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 the contentPane is
a BorderLayout manager. However, the JRootPane
uses a custom LayoutManager.
So, when you want to change the layout manager for the components you added
to a JRootPane, be sure to use code like this:
rootPane.getContentPane().setLayout(new BoxLayout());If a
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 hierarchy 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
Swing is not thread safe. For more information see Swing's Threading Policy.
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 JavaBeans
has been added to the java.beans package.
Please see java..
JLayeredPane, JMenuBar, JWindow, JFrame, JDialog, JInternalFrame, JComponent, BoxLayout, Mixing Heavy and Light Components
| Modifier and Type | Class and Description |
|---|---|
| protected class | JRootPane.
This class implements accessibility support for the
|
| protected class | JRootPane.
A custom layout manager that is responsible for the layout of layeredPane, glassPane, and menuBar. |
| Modifier and Type | Field and Description |
|---|---|
| public static final 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. |
| public static final int | ERROR_DIALOG
Constant used for the windowDecorationStyle property. |
| public static final int | FILE_CHOOSER_DIALOG
Constant used for the windowDecorationStyle property. |
| public static final 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. |
| private static final boolean | IGNORE_DISABLE_TRUE_DOUBLE_BUFFERING
Whether or not we should ignore requests to disable true double buffering. |
| public static final int | INFORMATION_DIALOG
Constant used for the windowDecorationStyle property. |
| protected JLayeredPane | layeredPane
The layered pane that manages the menu bar and content pane. |
| private static final boolean | LOG_DISABLE_TRUE_DOUBLE_BUFFERING
Whether or not we should dump the stack when true double buffering is disabled. |
| protected JMenuBar | menuBar
The menu bar. |
| public static final int | NONE
Constant used for the windowDecorationStyle property. |
| public static final int | PLAIN_DIALOG
Constant used for the windowDecorationStyle property. |
| public static final int | QUESTION_DIALOG
Constant used for the windowDecorationStyle property. |
| private static final String | |
| pack-priv boolean | useTrueDoubleBuffering
Whether or not true double buffering should be used. |
| public static final int | WARNING_DIALOG
Constant used for the windowDecorationStyle property. |
| private int |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| protected void | addImpl(Component
the component to be enhanced comp, Object the constraints to be respected constraints, int the index index)Overrides java. Overridden to enforce the position of the glass component as the zero child. |
| public void | addNotify()
Overrides javax. Notifies this component that it now has a parent component. |
| protected Container | Returns: the defaultcontentPaneCalled by the constructor methods to create the default
|
| protected Component | Returns: the defaultglassPaneCalled by the constructor methods to create the default
|
| protected JLayeredPane | Returns: the defaultlayeredPaneCalled by the constructor methods to create the default
|
| protected LayoutManager | Returns: the defaultlayoutManager.Called by the constructor methods to create the default
|
| pack-priv final void | |
| public AccessibleContext | Returns: anAccessibleJRootPane that serves as the
AccessibleContext of this JRootPaneOverrides java. Implements javax. Gets the |
| public Container | Returns: theContainer that holds the component-contentsReturns the content pane -- the container that holds the components parented by the root pane. |
| public JButton | Returns: theJButton which is currently the default buttonReturns the value of the |
| public Component | |
| public JMenuBar | |
| public JLayeredPane | Returns: theJLayeredPane currently in useGets the layered pane used by the root pane. |
| public JMenuBar | Returns: theJMenuBar used in the pane
Deprecated
As of Swing version 1.0.3
replaced by
getJMenuBar().
Returns the menu bar value. |
| public RootPaneUI | Returns: LabelUI objectOverrides javax. Returns the L&F object that renders this component. |
| public String | Returns: the string "RootPaneUI"Overrides javax. Returns a string that specifies the name of the L&F class that renders this component. |
| pack-priv final boolean | |
| public int | Returns: One ofNONE, FRAME,
PLAIN_DIALOG, INFORMATION_DIALOG,
ERROR_DIALOG, COLOR_CHOOSER_DIALOG,
FILE_CHOOSER_DIALOG, QUESTION_DIALOG or
WARNING_DIALOG.Returns a constant identifying the type of Window decorations the
|
| public boolean | Returns: true if this component's children don't overlapOverrides javax. The |
| public boolean | Returns: trueOverrides javax. If a descendant of this |
| protected String | Returns: a string representation of thisJRootPane.Overrides javax. Returns a string representation of this |
| public void | removeNotify()
Overrides javax. Notifies this component that it no longer has a parent component. |
| public void | setContentPane(Container
the content)Container to use for component-contentsSets the content pane -- the container that holds the components parented by the root pane. |
| public void | setDefaultButton(JButton
the defaultButton)JButton which is to be the default buttonSets the |
| public void | setDoubleBuffered(boolean aFlag)
Overrides javax. Sets whether this component should use a buffer to paint. |
| public void | setGlassPane(Component
the glass)Component to use as the glass pane
for this JRootPaneSets a specified |
| public void | |
| public void | |
| public void | setMenuBar(JMenuBar
the menu)JMenuBar to add.
Deprecated
As of Swing version 1.0.3
replaced by
setJMenuBar(JMenuBar menu).
Specifies the menu bar value. |
| public void | |
| pack-priv final void | |
| public void | setWindowDecorationStyle(int
Constant identifying Window decorations
to provide. windowDecorationStyle)Sets the type of Window decorations (such as borders, widgets for
closing a Window, title ...) the |
| public void | updateUI()
Overrides javax. Resets the UI property to a value from the current look and feel. |
| COLOR_CHOOSER_DIALOG | back to summary |
|---|---|
| public static final int COLOR_CHOOSER_DIALOG Constant used for the windowDecorationStyle property. Indicates that
the
| |
| contentPane | back to summary |
|---|---|
| protected Container contentPane The content pane. | |
| defaultButton | back to summary |
|---|---|
| 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. | |
| ERROR_DIALOG | back to summary |
|---|---|
| public static final int ERROR_DIALOG Constant used for the windowDecorationStyle property. Indicates that
the
| |
| FILE_CHOOSER_DIALOG | back to summary |
|---|---|
| public static final int FILE_CHOOSER_DIALOG Constant used for the windowDecorationStyle property. Indicates that
the
| |
| FRAME | back to summary |
|---|---|
| public static final int FRAME Constant used for the windowDecorationStyle property. Indicates that
the
| |
| glassPane | back to summary |
|---|---|
| protected Component glassPane The glass pane that overlays the menu bar and content pane, so it can intercept mouse movements and such. | |
| IGNORE_DISABLE_TRUE_DOUBLE_BUFFERING | back to summary |
|---|---|
| private static final boolean IGNORE_DISABLE_TRUE_DOUBLE_BUFFERING Whether or not we should ignore requests to disable true double buffering. Default is false. | |
| INFORMATION_DIALOG | back to summary |
|---|---|
| public static final int INFORMATION_DIALOG Constant used for the windowDecorationStyle property. Indicates that
the
| |
| layeredPane | back to summary |
|---|---|
| protected JLayeredPane layeredPane The layered pane that manages the menu bar and content pane. | |
| LOG_DISABLE_TRUE_DOUBLE_BUFFERING | back to summary |
|---|---|
| private static final boolean LOG_DISABLE_TRUE_DOUBLE_BUFFERING Whether or not we should dump the stack when true double buffering is disabled. Default is false. | |
| menuBar | back to summary |
|---|---|
| protected JMenuBar menuBar The menu bar. | |
| NONE | back to summary |
|---|---|
| public static final int NONE Constant used for the windowDecorationStyle property. Indicates that
the
| |
| PLAIN_DIALOG | back to summary |
|---|---|
| public static final int PLAIN_DIALOG Constant used for the windowDecorationStyle property. Indicates that
the
| |
| QUESTION_DIALOG | back to summary |
|---|---|
| public static final int QUESTION_DIALOG Constant used for the windowDecorationStyle property. Indicates that
the
| |
| uiClassID | back to summary |
|---|---|
| private static final String uiClassID | |
| useTrueDoubleBuffering | back to summary |
|---|---|
| pack-priv boolean useTrueDoubleBuffering Whether or not true double buffering should be used. This is typically true, but may be set to false in special situations. For example, heavy weight popups (backed by a window) set this to false. | |
| WARNING_DIALOG | back to summary |
|---|---|
| public static final int WARNING_DIALOG Constant used for the windowDecorationStyle property. Indicates that
the
| |
| windowDecorationStyle | back to summary |
|---|---|
| private int windowDecorationStyle | |
| JRootPane | back to summary |
|---|---|
| public JRootPane() Creates a | |
| addImpl | back to summary |
|---|---|
| protected void addImpl(Component comp, Object constraints, int index) Overrides java. Overridden to enforce the position of the glass component as the zero child. | |
| addNotify | back to summary |
|---|---|
| public void addNotify() Overrides javax. Doc from javax. Notifies this component that it now has a parent component.
When this method is invoked, the chain of parent components is
set up with | |
| createContentPane | back to summary |
|---|---|
| protected Container createContentPane() Called by the constructor methods to create the default
| |
| createGlassPane | back to summary |
|---|---|
| protected Component createGlassPane() Called by the constructor methods to create the default
| |
| createLayeredPane | back to summary |
|---|---|
| protected JLayeredPane createLayeredPane() Called by the constructor methods to create the default
| |
| createRootLayout | back to summary |
|---|---|
| protected LayoutManager createRootLayout() Called by the constructor methods to create the default
| |
| disableTrueDoubleBuffering | back to summary |
|---|---|
| pack-priv final void disableTrueDoubleBuffering() | |
| getAccessibleContext | back to summary |
|---|---|
| public AccessibleContext getAccessibleContext() Overrides java. Implements javax. Gets the
| |
| getContentPane | back to summary |
|---|---|
| public Container getContentPane() Returns the content pane -- the container that holds the components parented by the root pane.
| |
| getDefaultButton | back to summary |
|---|---|
| public JButton getDefaultButton() Returns the value of the
| |
| getGlassPane | back to summary |
|---|---|
| public Component getGlassPane() Returns the current glass pane for this
| |
| getJMenuBar | back to summary |
|---|---|
| public JMenuBar getJMenuBar() Returns the menu bar from the layered pane.
| |
| getLayeredPane | back to summary |
|---|---|
| public JLayeredPane getLayeredPane() Gets the layered pane used by the root pane. The layered pane
typically holds a content pane and an optional
| |
| getMenuBar | back to summary |
|---|---|
| public JMenuBar getMenuBar()
Deprecated As of Swing version 1.0.3
replaced by Returns the menu bar value.
| |
| getUI | back to summary |
|---|---|
| public RootPaneUI getUI() Overrides javax. Returns the L&F object that renders this component.
| |
| getUIClassID | back to summary |
|---|---|
| public String getUIClassID() Overrides javax. Returns a string that specifies the name of the L&F class that renders this component.
| |
| getUseTrueDoubleBuffering | back to summary |
|---|---|
| pack-priv final boolean getUseTrueDoubleBuffering() | |
| getWindowDecorationStyle | back to summary |
|---|---|
| public int getWindowDecorationStyle() Returns a constant identifying the type of Window decorations the
| |
| isOptimizedDrawingEnabled | back to summary |
|---|---|
| public boolean isOptimizedDrawingEnabled() Overrides javax. The
| |
| isValidateRoot | back to summary |
|---|---|
| public boolean isValidateRoot() Overrides javax. If a descendant of this
Deferred requests to layout a component and its descendents again.
For example, calls to
| |
| paramString | back to summary |
|---|---|
| protected String paramString() Overrides javax. Returns a string representation of this
| |
| removeNotify | back to summary |
|---|---|
| public void removeNotify() Overrides javax. Doc from javax. Notifies this component that it no longer has a parent component.
When this method is invoked, any | |
| setContentPane | back to summary |
|---|---|
| public void setContentPane(Container content) Sets the content pane -- the container that holds the components parented by the root pane.
Swing's painting architecture requires an opaque
| |
| setDefaultButton | back to summary |
|---|---|
| public void setDefaultButton(JButton defaultButton) Sets the
| |
| setDoubleBuffered | back to summary |
|---|---|
| public void setDoubleBuffered(boolean aFlag) Overrides javax. Doc from javax. Sets whether this component should use a buffer to paint.
If set to true, all the drawing from this component will be done
in an offscreen painting buffer. The offscreen painting buffer will
the be copied onto the screen.
If a
| |
| setGlassPane | back to summary |
|---|---|
| public void setGlassPane(Component glass) Sets a specified The new glass pane's visibility is changed to match that of the current glass pane. An implication of this is that care must be taken when you want to replace the glass pane and make it visible. Either of the following will work: root.setGlassPane(newGlassPane); newGlassPane.setVisible(true);or: root.getGlassPane().setVisible(true); root.setGlassPane(newGlassPane);
| |
| setJMenuBar | back to summary |
|---|---|
| public void setJMenuBar(JMenuBar menu) Adds or changes the menu bar used in the layered pane.
| |
| setLayeredPane | back to summary |
|---|---|
| public void setLayeredPane(JLayeredPane layered) Sets the layered pane for the root pane. The layered pane
typically holds a content pane and an optional
| |
| setMenuBar | back to summary |
|---|---|
| public void setMenuBar(JMenuBar menu)
Deprecated As of Swing version 1.0.3
replaced by Specifies the menu bar value.
| |
| setUI | back to summary |
|---|---|
| public void setUI(RootPaneUI ui) Sets the L&F object that renders this component.
| |
| setUseTrueDoubleBuffering | back to summary |
|---|---|
| pack-priv final void setUseTrueDoubleBuffering(boolean useTrueDoubleBuffering) | |
| setWindowDecorationStyle | back to summary |
|---|---|
| public void setWindowDecorationStyle(int windowDecorationStyle) Sets the type of Window decorations (such as borders, widgets for
closing a Window, title ...) the This is only a hint, and some look and feels may not support this. This is a bound property.
| |
| updateUI | back to summary |
|---|---|
| public void updateUI() Overrides javax. Resets the UI property to a value from the current look and feel.
| |
JRootPane class. It provides an implementation of the
Java Accessibility API appropriate to root pane user-interface elements.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 JavaBeans
has been added to the java.beans package.
Please see java..
| Access | Constructor and Description |
|---|---|
| protected |
| Modifier and Type | Method and Description |
|---|---|
| public Accessible | Returns: the Accessible child of the objectzero-based index of child i)Overrides javax. Returns the specified Accessible child of the object. |
| public int | Returns: the number of accessible children of the object.Overrides javax. Returns the number of accessible children of the object. |
| public AccessibleRole | Returns: an instance of AccessibleRole describing the role of the objectOverrides javax. Get the role of this object. |
| AccessibleJRootPane | back to summary |
|---|---|
| protected AccessibleJRootPane() Constructs an | |
| getAccessibleChild | back to summary |
|---|---|
| public Accessible getAccessibleChild(int i) Overrides javax. Returns the specified Accessible child of the object. The Accessible children of an Accessible object are zero-based, so the first child of an Accessible child is at index 0, the second child is at index 1, and so on.
| |
| getAccessibleChildrenCount | back to summary |
|---|---|
| public int getAccessibleChildrenCount() Overrides javax. Returns the number of accessible children of the object.
| |
| getAccessibleRole | back to summary |
|---|---|
| public AccessibleRole getAccessibleRole() Overrides javax. Get the role of this object.
| |
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 JavaBeans
has been added to the java.beans package.
Please see java..
| Access | Constructor and Description |
|---|---|
| protected |
| Modifier and Type | Method and Description |
|---|---|
| public void | addLayoutComponent(String name, Component comp)
Implements java. If the layout manager uses a per-component string,
adds the component |
| public void | addLayoutComponent(Component comp, Object constraints)
Implements java. Adds the specified component to the layout, using the specified constraint object. |
| public float | getLayoutAlignmentX(Container target)
Implements java. Returns the alignment along the x axis. |
| public float | getLayoutAlignmentY(Container target)
Implements java. Returns the alignment along the y axis. |
| public void | invalidateLayout(Container target)
Implements java. Invalidates the layout, indicating that if the layout manager has cached information it should be discarded. |
| public void | layoutContainer(Container
the Container for which this layout manager
is being used parent)Implements java. Instructs the layout manager to perform the layout for the specified container. |
| public Dimension | Returns: a Dimension object containing the layout's maximum sizethe Container for which this layout manager
is being used target)Implements java. Returns the maximum amount of space the layout can use. |
| public Dimension | Returns: a Dimension object containing the layout's minimum sizethe Container for which this layout manager
is being used parent)Implements java. Returns the minimum amount of space the layout needs. |
| public Dimension | Returns: a Dimension object containing the layout's preferred sizethe Container for which this layout manager
is being used parent)Implements java. Returns the amount of space the layout would like to have. |
| public void | removeLayoutComponent(Component comp)
Implements java. Removes the specified component from the layout. |
| RootLayout | back to summary |
|---|---|
| protected RootLayout() Constructs a | |
| addLayoutComponent | back to summary |
|---|---|
| public void addLayoutComponent(String name, Component comp) Implements java. Doc from java. If the layout manager uses a per-component string,
adds the component | |
| addLayoutComponent | back to summary |
|---|---|
| public void addLayoutComponent(Component comp, Object constraints) Implements java. Doc from java. Adds the specified component to the layout, using the specified constraint object. | |
| getLayoutAlignmentX | back to summary |
|---|---|
| public float getLayoutAlignmentX(Container target) Implements java. Doc from java. Returns the alignment along the x axis. This specifies how the component would like to be aligned relative to other components. The value should be a number between 0 and 1 where 0 represents alignment along the origin, 1 is aligned the furthest away from the origin, 0.5 is centered, etc. | |
| getLayoutAlignmentY | back to summary |
|---|---|
| public float getLayoutAlignmentY(Container target) Implements java. Doc from java. Returns the alignment along the y axis. This specifies how the component would like to be aligned relative to other components. The value should be a number between 0 and 1 where 0 represents alignment along the origin, 1 is aligned the furthest away from the origin, 0.5 is centered, etc. | |
| invalidateLayout | back to summary |
|---|---|
| public void invalidateLayout(Container target) Implements java. Doc from java. Invalidates the layout, indicating that if the layout manager has cached information it should be discarded. | |
| layoutContainer | back to summary |
|---|---|
| public void layoutContainer(Container parent) Implements java. Instructs the layout manager to perform the layout for the specified container.
| |
| maximumLayoutSize | back to summary |
|---|---|
| public Dimension maximumLayoutSize(Container target) Implements java. Returns the maximum amount of space the layout can use. | |
| minimumLayoutSize | back to summary |
|---|---|
| public Dimension minimumLayoutSize(Container parent) Implements java. Returns the minimum amount of space the layout needs. | |
| preferredLayoutSize | back to summary |
|---|---|
| public Dimension preferredLayoutSize(Container parent) Implements java. Returns the amount of space the layout would like to have. | |
| removeLayoutComponent | back to summary |
|---|---|
| public void removeLayoutComponent(Component comp) Implements java. Doc from java. Removes the specified component from the layout. | |