javax.swing
Class JRootPane

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.JRootPane
All Implemented Interfaces:
Accessible, ImageObserver, MenuContainer, Serializable

public class JRootPane
extends JComponent
implements Accessible

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.

The "heavyweight" components (those that delegate to a peer, or native component on the host system) are shown with a darker, heavier box. The four heavyweight JFC/Swing containers (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 5 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: The JComponent method getRootPane can be used to obtain the JRootPane that contains a given component.
The diagram at right shows the structure of a 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.

The contentPane must be the parent of any children of the JRootPane. Rather than adding directly to a JRootPane, like this:

       rootPane.add(child);
 
You instead add to the contentPane of the JRootPane, like this:
       rootPane.getContentPane().add(child);
 
The same priniciple 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. 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:

  1. The glassPane, if present, fills the entire viewable area of the JRootPane (bounds - insets).
  2. The layeredPane fills the entire viewable area of the JRootPane. (bounds - insets)
  3. The menuBar is positioned at the upper edge of the layeredPane().
  4. The contentPane fills the entire viewable area, minus the MenuBar, if present.
Any other views in the 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!

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. A future release of Swing will provide support for long term persistence.

See Also:
JLayeredPane, JMenuBar, JWindow, JFrame, JDialog, JApplet, JInternalFrame, JComponent, BoxLayout, Mixing Heavy and Light Components, Serialized Form

Inner Class Summary
protected  class JRootPane.AccessibleJRootPane
JRootPane.AccessibleJRootPane
This class implements accessibility support for the 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. A future release of Swing will provide support for long term persistence.

protected  class JRootPane.RootLayout
JRootPane.RootLayout
A custom layout manager that is responsible for the layout of layeredPane, glassPane, and menuBar.

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. A future release of Swing will provide support for long term persistence.

 
Inner classes inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Inner classes inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Inner classes inherited from class java.awt.Component
Component.AccessibleAWTComponent
 
Field Summary
protected  Container contentPane
copy->  contentPane
The content pane.
protected  JButton defaultButton
copy->  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
copy->  defaultPressAction
Deprecated. As of Java 2 platform v1.3.

As of Java 2 platform v1.3 this unusable field is no longer used. To override the default button you should replace the Action in the JRootPane's ActionMap. Please refer to the key bindings specification for further details.
See Also:
defaultButton
protected  javax.swing.JRootPane.DefaultAction defaultReleaseAction
copy->  defaultReleaseAction
Deprecated. As of Java 2 platform v1.3.

As of Java 2 platform v1.3 this unusable field is no longer used. To override the default button you should replace the Action in the JRootPane's ActionMap. Please refer to the key bindings specification for further details.
See Also:
defaultButton
protected  Component glassPane
copy->  glassPane
The glass pane that overlays the menu bar and content pane, so it can intercept mouse movements and such.
protected  JLayeredPane layeredPane
copy->  layeredPane
The layered pane that manages the menu bar and content pane.
protected  JMenuBar menuBar
copy->  menuBar
The menu bar.
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
JRootPane
copy->  new JRootPane()
copy->  <JRootPane var> = new JRootPane();
Create a JRootPane, setting up its glassPane, LayeredPane, and contentPane.
 
Method Summary
protected  void addImpl(Component comp, Object constraints, int index)
copy->  .addImpl(, , )
copy->  <JRootPane>.addImpl(<Component comp>, <Object constraints>, <int index>);
Overridden to enforce the position of the glass component as the zero child.
Overrides:
addImpl in class Container
Following copied from class: java.awt.Container
Parameters:
comp - the component to be added.
constraints - an object expressing layout contraints for this component.
index - the position in the container's list at which to insert the component, where -1 means insert at the end.
See Also:
Container.add(java.awt.Component), Container.add(java.awt.Component, int), Container.add(java.awt.Component, java.lang.Object), LayoutManager
 void addNotify()
copy->  .addNotify()
copy->  <JRootPane>.addNotify();
Register ourselves with the SystemEventQueueUtils as a new root pane.
Overrides:
addNotify in class JComponent
Following copied from class: javax.swing.JComponent
See Also:
JComponent.registerKeyboardAction(java.awt.event.ActionListener, java.lang.String, javax.swing.KeyStroke, int)
protected  Container createContentPane()
copy->  .createContentPane()
copy->  <Container var>=<JRootPane>.createContentPane();
Called by the constructor methods to create the default contentPane. By default this method creates a new JComponent add sets a BorderLayout as its LayoutManager.
protected  Component createGlassPane()
copy->  .createGlassPane()
copy->  <Component var>=<JRootPane>.createGlassPane();
Called by the constructor methods to create the default glassPane. By default this method creates a new JComponent with visibility set to false.
protected  JLayeredPane createLayeredPane()
copy->  .createLayeredPane()
copy->  <JLayeredPane var>=<JRootPane>.createLayeredPane();
Called by the constructor methods to create the default layeredPane. Bt default it creates a new JLayeredPane.
protected  LayoutManager createRootLayout()
copy->  .createRootLayout()
copy->  <LayoutManager var>=<JRootPane>.createRootLayout();
Called by the constructor methods to create the default layoutManager.
 AccessibleContext getAccessibleContext()
copy->  .getAccessibleContext()
copy->  <AccessibleContext var>=<JRootPane>.getAccessibleContext();
Gets the AccessibleContext associated with this JRootPane. For root panes, the AccessibleContext takes the form of an AccessibleJRootPane. A new AccessibleJRootPane instance is created if necessary.
Specified by:
getAccessibleContext in interface Accessible
Overrides:
getAccessibleContext in class JComponent
Returns:
an AccessibleJRootPane that serves as the AccessibleContext of this JRootPane
 Container getContentPane()
copy->  .getContentPane()
copy->  <Container var>=<JRootPane>.getContentPane();
Returns the content pane -- the container that holds the components parented by the root pane.
Returns:
the Container that holds the component-contents
 JButton getDefaultButton()
copy->  .getDefaultButton()
copy->  <JButton var>=<JRootPane>.getDefaultButton();
Returns the current default button for this JRootPane.
Returns:
the JButton which is currently the default button
 Component getGlassPane()
copy->  .getGlassPane()
copy->  <Component var>=<JRootPane>.getGlassPane();
Returns the current glass pane for this JRootPane.
Returns:
the current glass pane.
See Also:
setGlassPane(java.awt.Component)
 JMenuBar getJMenuBar()
copy->  .getJMenuBar()
copy->  <JMenuBar var>=<JRootPane>.getJMenuBar();
Returns the menu bar from the layered pane.
Returns:
the JMenuBar used in the pane
 JLayeredPane getLayeredPane()
copy->  .getLayeredPane()
copy->  <JLayeredPane var>=<JRootPane>.getLayeredPane();
Get the layered pane used by the root pane. The layered pane typically holds a content pane and an optional JMenuBar.
Returns:
the JLayeredPane currently in use
 JMenuBar getMenuBar()
copy->  .getMenuBar()
copy->  <JMenuBar var>=<JRootPane>.getMenuBar();
Deprecated. As of Swing version 1.0.3 replaced by getJMenubar().

Returns the menu bar value.
 RootPaneUI getUI()
copy->  .getUI()
copy->  <RootPaneUI var>=<JRootPane>.getUI();
Returns the L&F object that renders this component.
Returns:
LabelUI object
Since:
1.3
 String getUIClassID()
copy->  .getUIClassID()
copy->  <String var>=<JRootPane>.getUIClassID();
Returns a string that specifies the name of the l&f class that renders this component.
Overrides:
getUIClassID in class JComponent
Returns:
String "RootPaneUI"
See Also:
JComponent.getUIClassID(), UIDefaults.getUI(javax.swing.JComponent)
 boolean isFocusCycleRoot()
copy->  .isFocusCycleRoot()
copy->  <boolean var>=<JRootPane>.isFocusCycleRoot();
Make JRootPane be the root of a focus cycle. That means that, by default, tabbing within the root pane will move between components of the pane, but not out of the pane.
Overrides:
isFocusCycleRoot in class JComponent
Returns:
true
See Also:
JComponent.isFocusCycleRoot()
 boolean isOptimizedDrawingEnabled()
copy->  .isOptimizedDrawingEnabled()
copy->  <boolean var>=<JRootPane>.isOptimizedDrawingEnabled();
The GlassPane and ContentPane have the same bounds, which means JRootPane does not tiles its children and this should return false. On the other hand, the GlassPane is normally not visible, and so this can return true if the GlassPane isn't visible. Therefore, the return value here depends upon the visiblity of the GlassPane.
Overrides:
isOptimizedDrawingEnabled in class JComponent
Returns:
true if this component's children don't overlap
 boolean isValidateRoot()
copy->  .isValidateRoot()
copy->  <boolean var>=<JRootPane>.isValidateRoot();
If a descendant of this JRootPane calls revalidate, validate from here on down.

Deferred requests to relayout a component and it's descendants, i.e. calls to revalidate(), are pushed upwards to either a JRootPane or a JScrollPane because both classes override isValidateRoot() to return true.

Overrides:
isValidateRoot in class JComponent
Returns:
true
See Also:
JComponent.isValidateRoot()
protected  String paramString()
copy->  .paramString()
copy->  <String var>=<JRootPane>.paramString();
Returns a string representation of this JRootPane. This method is intended to be used only for debugging purposes, and the content and format of the returned string may vary between implementations. The returned string may be empty but may not be null.
Overrides:
paramString in class JComponent
Returns:
a string representation of this JRootPane.
 void removeNotify()
copy->  .removeNotify()
copy->  <JRootPane>.removeNotify();
Unregister ourselves from SystemEventQueueUtils.
Overrides:
removeNotify in class JComponent
See Also:
addNotify()
 void setContentPane(Container content)
copy->  .setContentPane( )
copy->  <JRootPane>.setContentPane(<Container content>);
Sets the content pane -- the container that holds the components parented by the root pane.
Parameters:
content - the Container to use for component-contents
Throws:
IllegalComponentStateException - (a runtime exception) if the content pane parameter is null
 void setDefaultButton(JButton defaultButton)
copy->  .setDefaultButton( )
copy->  <JRootPane>.setDefaultButton(<JButton defaultButton>);
Sets the current default button for this JRootPane. The default button is the button which will be activated when a UI-defined activation event (typically the Enter key) occurs in the RootPane regardless of whether or not the button has keyboard focus (unless there is another component within the RootPane which consumes the activation event, such as a JTextPane). For default activation to work, the button must be an enabled descendent of the RootPane when activation occurs. To remove a default button from this RootPane, set this property to null.
Parameters:
default - the JButton which is to be the default button
See Also:
JButton.isDefaultButton()
 void setGlassPane(Component glass)
copy->  .setGlassPane( )
copy->  <JRootPane>.setGlassPane(<Component glass>);
Sets a specified Component to be the glass pane for this root pane. The glass pane should normally be a lightweight, transparent component, because it will be made visible when ever the root pane needs to grab input events. For example, only one JInternalFrame is ever active when using a DefaultDesktop, and any inactive JInternalFrames' glass panes are made visible so that clicking anywhere within an inactive JInternalFrame can activate it.
Parameters:
glass - the Component to use as the glass pane for this JRootPane.
 void setJMenuBar(JMenuBar menu)
copy->  .setJMenuBar( )
copy->  <JRootPane>.setJMenuBar(<JMenuBar menu>);
Adds or changes the menu bar used in the layered pane.
Parameters:
menu - the JMenuBar to add
 void setLayeredPane(JLayeredPane layered)
copy->  .setLayeredPane( )
copy->  <JRootPane>.setLayeredPane(<JLayeredPane layered>);
Set the layered pane for the root pane. The layered pane typically holds a content pane and an optional JMenuBar.
Parameters:
layered - the JLayeredPane to use.
Throws:
IllegalComponentStateException - (a runtime exception) if the layered pane parameter is null
 void setMenuBar(JMenuBar menu)
copy->  .setMenuBar( )
copy->  <JRootPane>.setMenuBar(<JMenuBar menu>);
Deprecated. As of Swing version 1.0.3 replaced by setJMenuBar(JMenuBar menu).

Specifies the menu bar value.
 void setUI(RootPaneUI ui)
copy->  .setUI( )
copy->  <JRootPane>.setUI(<RootPaneUI ui>);
Sets the L&F object that renders this component.
Parameters:
ui - the LabelUI L&F object
Since:
1.3
See Also:
UIDefaults.getUI(javax.swing.JComponent)
 void updateUI()
copy->  .updateUI()
copy->  <JRootPane>.updateUI();
Notification from the UIFactory that the L&F has changed.
Overrides:
updateUI in class JComponent
See Also:
JComponent.updateUI()
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getVerifyInputWhenFocusTarget, getWidth, getVisibleRect, getX, getY, grabFocus, hasFocus, hide, isDoubleBuffered, isFocusTraversable, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processFocusEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getLayout, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setLayout, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, imageUpdate, inside, isDisplayable, isEnabled, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait