|
JavaTM 2 Platform Standard Edition |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.awt.Component | +--java.awt.Container | +--javax.swing.JComponent | +--javax.swing.JRootPane
The fundamental component in the container hierarchy. In the same way that JComponent is fundamental to the JFC/Swing components, JRootPane is fundamental to the JFC/Swing window, frame, and pane containers. However, while other classes use inheritance to take advantage of JComponent's capabilities, the container classes delegate operations to a JRootPane instance. Those containers are the heavyweight containers: JFrame, JDialog, JWindow, and JApplet, as well as the lightweight container, JInternalFrame.
The following image shows these relationships:
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.
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 theIf a JMenuBar component is set on the JRootPane, it is positioned along the upper edge of the frame. ThecontentPane
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());
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:
glassPane
, if present, 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.
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.
JLayeredPane
,
JMenuBar
,
JWindow
,
JFrame
,
JDialog
,
JApplet
,
JInternalFrame
,
JComponent
,
BoxLayout
,
Mixing Heavy and Light Components, Serialized FormInner Class Summary | |
protected class |
JRootPane.AccessibleJRootPane
The class used to obtain the accessible role for this object. |
protected class |
JRootPane.RootLayout
A custom layout manager that is responsible for the layout of layeredPane, glassPane, and menuBar. |
Inner classes inherited from class javax.swing.JComponent |
JComponent.AccessibleJComponent |
Field Summary | |
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
The action to take when the defaultButton is pressed. |
protected javax.swing.JRootPane.DefaultAction |
defaultReleaseAction
The action to take when the defaultButton is released. |
protected Component |
glassPane
The glass pane that overlays the menu bar and content pane, so it can intercept mouse movements and such. |
protected JLayeredPane |
layeredPane
The layered pane that manages the menu bar and content pane. |
protected JMenuBar |
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 |
Constructor Summary | |
JRootPane()
Create a JRootPane, setting up its glassPane, LayeredPane, and contentPane. |
Method Summary | |
protected void |
addImpl(Component comp,
Object constraints,
int index)
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. |
Component |
findComponentAt(int x,
int y)
Locates the visible child component that contains the specified position. |
AccessibleContext |
getAccessibleContext()
Get the AccessibleContext associated with this JComponent |
Container |
getContentPane()
Returns the content pane -- the container that holds the components parented by the root pane. |
JButton |
getDefaultButton()
Returns the current default button for this JRootPane. |
Component |
getGlassPane()
Returns the current glass pane for this JRootPane. |
JMenuBar |
getJMenuBar()
Returns the menu bar from the layered pane. |
JLayeredPane |
getLayeredPane()
Get the layered pane used by the root pane. |
JMenuBar |
getMenuBar()
Deprecated. As of Swing version 1.0.3 replaced by getJMenubar() . |
boolean |
isFocusCycleRoot()
Make JRootPane be the root of a focus cycle. |
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(Container content)
Sets the content pane -- the container that holds the components parented by the root pane. |
void |
setDefaultButton(JButton defaultButton)
Sets the current default button for this JRootPane. |
void |
setGlassPane(Component glass)
Sets a specified Component to be the glass pane for this root pane. |
void |
setJMenuBar(JMenuBar menu)
Adds or changes the menu bar used in the layered pane. |
void |
setLayeredPane(JLayeredPane layered)
Set the layered pane for the root pane. |
void |
setMenuBar(JMenuBar menu)
Deprecated. As of Swing version 1.0.3 replaced by setJMenuBar(JMenuBar menu) . |
Methods inherited from class java.awt.Container |
add,
add,
add,
add,
add,
addContainerListener,
countComponents,
deliverEvent,
doLayout,
findComponentAt,
getComponent,
getComponentAt,
getComponentAt,
getComponentCount,
getComponents,
getLayout,
insets,
invalidate,
isAncestorOf,
layout,
list,
list,
locate,
minimumSize,
paintComponents,
preferredSize,
print,
printComponents,
processContainerEvent,
processEvent,
remove,
remove,
removeAll,
removeContainerListener,
setCursor,
setLayout,
validate,
validateTree |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
wait,
wait,
wait |
Field Detail |
protected JMenuBar menuBar
protected Container contentPane
protected JLayeredPane layeredPane
protected Component glassPane
protected JButton defaultButton
protected javax.swing.JRootPane.DefaultAction defaultPressAction
defaultButton
protected javax.swing.JRootPane.DefaultAction defaultReleaseAction
defaultButton
Constructor Detail |
public JRootPane()
Method Detail |
protected JLayeredPane createLayeredPane()
protected Container createContentPane()
protected Component createGlassPane()
protected LayoutManager createRootLayout()
public void setJMenuBar(JMenuBar menu)
menu
- the JMenuBar to addpublic void setMenuBar(JMenuBar menu)
setJMenuBar(JMenuBar menu)
.
public JMenuBar getJMenuBar()
public JMenuBar getMenuBar()
getJMenubar()
.
public void setContentPane(Container content)
content
- the Container to use for component-contentspublic Container getContentPane()
public void setLayeredPane(JLayeredPane layered)
layered
- the JLayeredPane to use.public JLayeredPane getLayeredPane()
public void setGlassPane(Component glass)
glass
- the Component to use as the glass pane for this
JRootPane.public Component getGlassPane()
setGlassPane(java.awt.Component)
public boolean isFocusCycleRoot()
JComponent.isFocusCycleRoot()
public boolean isValidateRoot()
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.
JComponent.isValidateRoot()
public void addNotify()
public void removeNotify()
public void setDefaultButton(JButton defaultButton)
default
- the JButton which is to be the default buttonJButton.isDefaultButton()
public JButton getDefaultButton()
protected void addImpl(Component comp, Object constraints, int index)
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.Container.add(java.awt.Component)
,
Container.add(java.awt.Component, int)
,
Container.add(java.awt.Component, java.lang.Object)
,
LayoutManager
public Component findComponentAt(int x, int y)
This method is similar to Container.findComponentAt, except that the JRootPane.glassPane is ignored during the search. This is needed to to support drag&drop. Since the glassPane is the same size as the JRootPane instance, if there's a need to test whether the mouse is over the glassPane, just test that it's over the JRootPane instead.
x
- the x coordinatey
- the yReturns:Container.findComponentAt
,
Container.getComponentAt
protected String paramString()
null
.public AccessibleContext getAccessibleContext()
|
JavaTM 2 Platform Standard Edition |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |