JavaTM 2 Platform
Standard Ed. 6

javax.swing
类 JRootPane

java.lang.Object
  继承者 java.awt.Component
      继承者 java.awt.Container
          继承者 javax.swing.JComponent
              继承者 javax.swing.JRootPane
所有已实现的接口:
ImageObserver, MenuContainer, Serializable, Accessible

public class JRootPane
extends JComponent
implements Accessible

该轻量级容器由 JFrameJDialogJWindowJAppletJInternalFrame 在后台使用。有关根窗格所提供功能的面向任务的信息,请参阅 The Java Tutorial 中的 How to Use Root Panes 一节。

下面的图像显示了使用根窗格的各个类之间的关系。

以下文本是对此图像的描述。

“重量级”组件(指委托给主机系统上的同位体或本地组件的组件)用较暗的、更重的框来显示。四个重量级 JFC/Swing 容器(JFrameJDialogJWindowJApplet)的显示与它们扩展的 AWT 类有关。这四个组件是 Swing 库中仅有的重量级容器。这里还显示了轻量级容器 JInternalFrame。所有这五个 JFC/Swing 容器都实现 RootPaneContainer 接口,并且它们都将其操作委托给 JRootPane(顶端显示有一个小 "handle")。
注:使用 JComponentgetRootPane 方法可获取包含给定组件的 JRootPane
以下文本是对此图像的描述。
右图显示了 JRootPane 的结构。JRootpane 由一个 glassPane 和一个可选的 menuBar 以及一个 contentPane 组成。(JLayeredPane 负责管理 menuBarcontentPane。)glassPane 位于所有窗格之上,以便能够截取鼠标移动。由于 glassPane(与 contentPane 类似)可以是一个任意的组件,也可以设置 glassPane 来进行绘制。这样 glassPane 上的线条和图像可涵盖其下的窗体,不受其边界的限制。

尽管 menuBar 组件为可选,但 layeredPanecontentPaneglassPane 总是存在的。试图将它们设置为 null 将生成异常。

要将组件添加到 JRootPane(可选的菜单栏除外),您可以将对象添加到 JRootPanecontentPane,如下所示:

       rootPane.getContentPane().add(child);
 
可用同样的方法设置布局管理器、移除组件以及列出子级等。所有这些方法都是在 contentPane 上而不是 JRootPane 上调用的。
注:contentPane 的默认布局管理器是 BorderLayout 管理器。但是,JRootPane 使用一个自定义的 LayoutManager。所以,如果您希望更改已添加到 JRootPane 中的组件的布局管理器,一定要确保使用如下代码:
    rootPane.getContentPane().setLayout(new BoxLayout());
 
如果已在 JRootPane 上设置了 JMenuBar 组件,它将沿窗体的上边缘放置。contentPane 的位置和大小将进行调整以填充剩余的区域。(JMenuBarcontentPane 被添加到位于 JLayeredPane.FRAME_CONTENT_LAYER 层的 layeredPane 组件中。)

layeredPaneJRootPane 中所有子级的父级,既是菜单的直接父级,又是添加到 contentPane 中的所有组件的祖父级。它是 JLayeredPane 的实例,提供在若干层上添加组件的能力。在处理弹出菜单、对话框以及拖动时,即要求将组件置于窗格中所有其它组件之上的情况下,此功能非常有用。

glassPane 位于 JRootPane 中所有其它组件之上。这为在所有其它组件上绘图和截取鼠标事件提供了方便,这对拖动和绘图都非常有用。开发人员可在 glassPane 上使用 setVisible 控制 glassPane 在所有其它子级上面显示的时间。默认情况下,glassPane 为不可见。

JRootPane 所使用的自定义 LayoutManager 可确保:

  1. glassPane 填充了 JRootPane 的整个可查看区域(边界 - insets)。
  2. layeredPane 填充了 JRootPane 的整个可查看区域。(边界 - insets)
  3. menuBar 位于 layeredPane 的上边缘。
  4. contentPane 填充了整个可查看区域,减去 menuBar(如果有)。
JRootPane 视图层次结构中的任何其它视图均忽略。

如果您替换 JRootPaneLayoutManager,您将负责管理所有这些视图。所以通常情况下,应该确保更改的是 contentPane 的布局管理器,而不是 JRootPane 自身的布局管理器。

Swing 的绘制架构要求在所有其它组件之上的包含层次结构中有一个不透明的 JComponent。这通常通过使用内容窗格来实现。如果要替换内容窗格,建议使用 setOpaque(true) 将内容窗格设置为不透明。另外,如果内容窗格重写 paintComponent,还需要在 paintComponent 中用不透明颜色将背景完全填充。

警告:Swing 不是线程安全的。有关更多信息,请参阅 Swing's Threading Policy

警告:此类的序列化对象与以后的 Swing 版本不兼容。当前序列化支持适用于短期存储,或适用于在运行相同 Swing 版本的应用程序之间进行 RMI(Remote Method Invocation,远程方法调用)。从 1.4 版本开始,已在 java.beans 包中添加了支持所有 JavaBeansTM 长期存储的功能。请参见 XMLEncoder

另请参见:
JLayeredPane, JMenuBar, JWindow, JFrame, JDialog, JApplet, JInternalFrame, JComponent, BoxLayout, Mixing Heavy and Light Components

嵌套类摘要
protected  class JRootPane.AccessibleJRootPane
          此类实现对 JRootPane 类的可访问性支持。
protected  class JRootPane.RootLayout
          该自定义布局管理器负责 layeredPane、glassPane 和 menuBar 的布局。
 
从类 javax.swing.JComponent 继承的嵌套类/接口
JComponent.AccessibleJComponent
 
从类 java.awt.Container 继承的嵌套类/接口
Container.AccessibleAWTContainer
 
从类 java.awt.Component 继承的嵌套类/接口
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
字段摘要
static int COLOR_CHOOSER_DIALOG
          供 windowDecorationStyle 属性使用的常量。
protected  Container contentPane
          内容窗格。
protected  JButton defaultButton
          当窗格成为焦点并有类似按下 Enter 键的特定于 UI 的操作发生时被激活的按钮。
protected  javax.swing.JRootPane.DefaultAction defaultPressAction
          已过时。 从 Java 2 platform v1.3 开始
protected  javax.swing.JRootPane.DefaultAction defaultReleaseAction
          已过时。 从 Java 2 platform v1.3 开始
static int ERROR_DIALOG
          供 windowDecorationStyle 属性使用的常量。
static int FILE_CHOOSER_DIALOG
          供 windowDecorationStyle 属性使用的常量。
static int FRAME
          供 windowDecorationStyle 属性使用的常量。
protected  Component glassPane
          覆盖菜单栏和内容窗格的玻璃窗格,便于截取鼠标移动等操作。
static int INFORMATION_DIALOG
          供 windowDecorationStyle 属性使用的常量。
protected  JLayeredPane layeredPane
          管理菜单栏和内容窗格的分层窗格。
protected  JMenuBar menuBar
          菜单栏。
static int NONE
          供 windowDecorationStyle 属性使用的常量。
static int PLAIN_DIALOG
          供 windowDecorationStyle 属性使用的常量。
static int QUESTION_DIALOG
          供 windowDecorationStyle 属性使用的常量。
static int WARNING_DIALOG
          供 windowDecorationStyle 属性使用的常量。
 
从类 javax.swing.JComponent 继承的字段
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
从类 java.awt.Component 继承的字段
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
从接口 java.awt.image.ImageObserver 继承的字段
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
构造方法摘要
JRootPane()
          创建 JRootPane,设置其 glassPanelayeredPane 以及 contentPane
 
方法摘要
protected  void addImpl(Component comp, Object constraints, int index)
          重写以便将玻璃组件的位置强行设置成零位子级。
 void addNotify()
          将本身注册为 SystemEventQueueUtils 的新的根窗格。
protected  Container createContentPane()
          由构造方法调用以便创建默认的 contentPane
protected  Component createGlassPane()
          由构造方法调用以便创建默认的 glassPane
protected  JLayeredPane createLayeredPane()
          由构造方法调用以便创建默认的 layeredPane
protected  LayoutManager createRootLayout()
          由构造方法调用以便创建默认的 layoutManager
 AccessibleContext getAccessibleContext()
          获取与此 JRootPane 相关联的 AccessibleContext
 Container getContentPane()
          返回内容窗格,它是保存以根窗格为父级的组件的容器。
 JButton getDefaultButton()
          返回 defaultButton 属性的值。
 Component getGlassPane()
          返回此 JRootPane 的当前玻璃窗格。
 JMenuBar getJMenuBar()
          返回窗格层的菜单栏。
 JLayeredPane getLayeredPane()
          获取供根窗格使用的分层窗格。
 JMenuBar getMenuBar()
          已过时。 从 Swing 版本 1.0.3 开始,由 getJMenuBar() 取代。
 RootPaneUI getUI()
          返回呈现此组件的 L&F 对象。
 String getUIClassID()
          返回一个指定呈现此组件的 L&F 类名称的字符串。
 int getWindowDecorationStyle()
          返回一个常量,它标识 JRootPane 提供的 Window 装饰类型。
 boolean isOptimizedDrawingEnabled()
          glassPanecontentPane 具有相同的边界,这意味着 JRootPane 并不对其子级平铺,应返回 false。
 boolean isValidateRoot()
          如果此 JRootPane 的一个后代调用 revalidate,将从此位置开始进行验证。
protected  String paramString()
          返回此 JRootPane 的字符串表示形式。
 void removeNotify()
          将本身从 SystemEventQueueUtils 注销。
 void setContentPane(Container content)
          设置内容窗格,它是保存以根窗格为父级的组件的容器。
 void setDefaultButton(JButton defaultButton)
          设置 defaultButton 属性,它确定此 JRootPane 的当前默认按钮。
 void setDoubleBuffered(boolean aFlag)
          设置此组件是否应该使用缓冲区进行绘制。
 void setGlassPane(Component glass)
          将指定的 Component 设置为此根窗格的玻璃窗格。
 void setJMenuBar(JMenuBar menu)
          添加或更改在分层窗格中使用的菜单栏。
 void setLayeredPane(JLayeredPane layered)
          设置供根窗格使用的分层窗格。
 void setMenuBar(JMenuBar menu)
          已过时。 从 Swing 版本 1.0.3 开始,由 setJMenuBar(JMenuBar menu) 取代。
 void setUI(RootPaneUI ui)
          设置呈现此组件的 L&F 对象。
 void setWindowDecorationStyle(int windowDecorationStyle)
          设置 JRootPane 应提供的 Window 装饰类型(例如,边界、关闭 Window 的小部件、标题等)。
 void updateUI()
          将 UI 属性重置为当前外观对应的值。
 
从类 javax.swing.JComponent 继承的方法
addAncestorListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
从类 java.awt.Container 继承的方法
add, add, add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
从类 java.awt.Component 继承的方法
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

字段详细信息

NONE

public static final int NONE
供 windowDecorationStyle 属性使用的常量。指示 JRootPane 不应提供任何类型的 Window 装饰。

从以下版本开始:
1.4
另请参见:
常量字段值

FRAME

public static final int FRAME
供 windowDecorationStyle 属性使用的常量。指示 JRootPane 应提供适合 Frame 的装饰。

从以下版本开始:
1.4
另请参见:
常量字段值

PLAIN_DIALOG

public static final int PLAIN_DIALOG
供 windowDecorationStyle 属性使用的常量。指示 JRootPane 应提供适合 Dialog 的装饰。

从以下版本开始:
1.4
另请参见:
常量字段值

INFORMATION_DIALOG

public static final int INFORMATION_DIALOG
供 windowDecorationStyle 属性使用的常量。指示 JRootPane 应提供适合 Dialog 的装饰以便显示一条报告消息。

从以下版本开始:
1.4
另请参见:
常量字段值

ERROR_DIALOG

public static final int ERROR_DIALOG
供 windowDecorationStyle 属性使用的常量。指示 JRootPane 应提供适合 Dialog 的装饰以便显示一条错误消息。

从以下版本开始:
1.4
另请参见:
常量字段值

COLOR_CHOOSER_DIALOG

public static final int COLOR_CHOOSER_DIALOG
供 windowDecorationStyle 属性使用的常量。指示 JRootPane 应提供适合 Dialog 的装饰以便显示 JColorChooser

从以下版本开始:
1.4
另请参见:
常量字段值

FILE_CHOOSER_DIALOG

public static final int FILE_CHOOSER_DIALOG
供 windowDecorationStyle 属性使用的常量。指示 JRootPane 应提供适合 Dialog 的装饰以便显示 JFileChooser

从以下版本开始:
1.4
另请参见:
常量字段值

QUESTION_DIALOG

public static final int QUESTION_DIALOG
供 windowDecorationStyle 属性使用的常量。指示 JRootPane 应提供适合 Dialog 的装饰以便向用户显示一个问题。

从以下版本开始:
1.4
另请参见:
常量字段值

WARNING_DIALOG

public static final int WARNING_DIALOG
供 windowDecorationStyle 属性使用的常量。指示 JRootPane 应提供适合 Dialog 的装饰以便显示一条警告消息。

从以下版本开始:
1.4
另请参见:
常量字段值

menuBar

protected JMenuBar menuBar
菜单栏。


contentPane

protected Container contentPane
内容窗格。


layeredPane

protected JLayeredPane layeredPane
管理菜单栏和内容窗格的分层窗格。


glassPane

protected Component glassPane
覆盖菜单栏和内容窗格的玻璃窗格,便于截取鼠标移动等操作。


defaultButton

protected JButton defaultButton
当窗格成为焦点并有类似按下 Enter 键的特定于 UI 的操作发生时被激活的按钮。


defaultPressAction

@Deprecated
protected javax.swing.JRootPane.DefaultAction defaultPressAction
已过时。 从 Java 2 platform v1.3 开始
从 Java 2 platform v1.3 开始,此无用字段已不再使用。要重写默认的按钮,应在 JRootPaneActionMap 中替换 Action。有关更多详细信息,请参阅键绑定规范。

另请参见:
defaultButton

defaultReleaseAction

@Deprecated
protected javax.swing.JRootPane.DefaultAction defaultReleaseAction
已过时。 从 Java 2 platform v1.3 开始
从 Java 2 platform v1.3 开始,此无用字段已不再使用。要重写默认的按钮,应在 JRootPaneActionMap 中替换 Action。有关更多详细信息,请参阅键绑定规范。

另请参见:
defaultButton
构造方法详细信息

JRootPane

public JRootPane()
创建 JRootPane,设置其 glassPanelayeredPane 以及 contentPane

方法详细信息

setDoubleBuffered

public void setDoubleBuffered(boolean aFlag)
设置此组件是否应该使用缓冲区进行绘制。如果设置为 true,则此组件的所有绘制将在一个离屏绘制缓冲区内完成。然后将该离屏绘制缓冲区复制到屏幕上。如果缓冲了某个 Component,并且还缓冲了它的某个祖先,则将使用该祖先缓冲区。

覆盖:
JComponent 中的 setDoubleBuffered
参数:
aFlag - 如果为 true,则设置此组件使用双缓冲区进行缓冲
从以下版本开始:
1.6

getWindowDecorationStyle

public int getWindowDecorationStyle()
返回一个常量,它标识 JRootPane 提供的 Window 装饰类型。

返回:
NONEFRAMEPLAIN_DIALOGINFORMATION_DIALOGERROR_DIALOGCOLOR_CHOOSER_DIALOGFILE_CHOOSER_DIALOGQUESTION_DIALOGWARNING_DIALOG 之一。
从以下版本开始:
1.4
另请参见:
setWindowDecorationStyle(int)

setWindowDecorationStyle

public void setWindowDecorationStyle(int windowDecorationStyle)
设置 JRootPane 应提供的 Window 装饰类型(例如,边界、关闭 Window 的小部件、标题等)。默认不提供任何 Window 装饰 (NONE)。

这只是一个提示,有些外观可能不支持。这是一个绑定属性。

参数:
windowDecorationStyle - 标识要提供的 Window 装饰的常量。
抛出:
IllegalArgumentException - 如果 style 不是下列常量之一:NONEFRAMEPLAIN_DIALOGINFORMATION_DIALOGERROR_DIALOGCOLOR_CHOOSER_DIALOGFILE_CHOOSER_DIALOGQUESTION_DIALOGWARNING_DIALOG
从以下版本开始:
1.4
另请参见:
JDialog.setDefaultLookAndFeelDecorated(boolean), JFrame.setDefaultLookAndFeelDecorated(boolean), LookAndFeel.getSupportsWindowDecorations()

getUI

public RootPaneUI getUI()
返回呈现此组件的 L&F 对象。

返回:
LabelUI 对象
从以下版本开始:
1.3

setUI

public void setUI(RootPaneUI ui)
设置呈现此组件的 L&F 对象。

参数:
ui - LabelUI L&F 对象
从以下版本开始:
1.3
另请参见:
UIDefaults.getUI(javax.swing.JComponent)

updateUI

public void updateUI()
将 UI 属性重置为当前外观对应的值。

覆盖:
JComponent 中的 updateUI
另请参见:
JComponent.updateUI()

getUIClassID

public String getUIClassID()
返回一个指定呈现此组件的 L&F 类名称的字符串。

覆盖:
JComponent 中的 getUIClassID
返回:
"RootPaneUI" 字符串
另请参见:
JComponent.getUIClassID(), UIDefaults.getUI(javax.swing.JComponent)

createLayeredPane

protected JLayeredPane createLayeredPane()
由构造方法调用以便创建默认的 layeredPane。默认情况下创建一个新的 JLayeredPane

返回:
默认的 layeredPane

createContentPane

protected Container createContentPane()
由构造方法调用以便创建默认的 contentPane。默认情况下,此方法创建新的 JComponent 并将 BorderLayout 设置为它的 LayoutManager

返回:
默认的 contentPane

createGlassPane

protected Component createGlassPane()
由构造方法调用以便创建默认的 glassPane。默认情况下,此方法创建新的 JComponent,其可见性设置为 false。

返回:
默认的 glassPane

createRootLayout

protected LayoutManager createRootLayout()
由构造方法调用以便创建默认的 layoutManager

返回:
默认的 layoutManager.

setJMenuBar

public void setJMenuBar(JMenuBar menu)
添加或更改在分层窗格中使用的菜单栏。

参数:
menu - 要添加的 JMenuBar

setMenuBar

@Deprecated
public void setMenuBar(JMenuBar menu)
已过时。 从 Swing 版本 1.0.3 开始,由 setJMenuBar(JMenuBar menu) 取代。

指定菜单栏的值。

参数:
menu - 要添加的 JMenuBar

getJMenuBar

public JMenuBar getJMenuBar()
返回窗格层的菜单栏。

返回:
该窗格中使用的 JMenuBar

getMenuBar

@Deprecated
public JMenuBar getMenuBar()
已过时。 从 Swing 版本 1.0.3 开始,由 getJMenuBar() 取代。

返回菜单栏的值。

返回:
窗格中使用的 JMenuBar

setContentPane

public void setContentPane(Container content)
设置内容窗格,它是保存以根窗格为父级的组件的容器。

Swing 的绘制架构要求在包含层次结构中有一个不透明的 JComponent。这通常由内容窗格提供。如果要替换内容窗格,则建议用一个不透明的 JComponent 来替代。

参数:
content - 供组件内容使用的 Container
抛出:
IllegalComponentStateException - (运行时异常)如果内容窗格参数为 null

getContentPane

public Container getContentPane()
返回内容窗格,它是保存以根窗格为父级的组件的容器。

返回:
保存组件内容的 Container

setLayeredPane

public void setLayeredPane(JLayeredPane layered)
设置供根窗格使用的分层窗格。分层窗格通常容纳一个内容窗格和一个可选的 JMenuBar

参数:
layered - 要使用的 JLayeredPane
抛出:
IllegalComponentStateException - (运行时异常)如果分层窗格参数为 null

getLayeredPane

public JLayeredPane getLayeredPane()
获取供根窗格使用的分层窗格。分层窗格通常保存一个内容窗格和一个可选的 JMenuBar

返回:
当前使用的 JLayeredPane

setGlassPane

public void setGlassPane(Component glass)
将指定的 Component 设置为此根窗格的玻璃窗格。玻璃窗格通常应该是一个轻量级的、透明的组件,因为每当根窗格需要抓取输入事件时会将它设置为可见。

更改新玻璃窗格的可见性,以匹配当前玻璃窗格的可见性。其含义是,当想要替换玻璃窗格并使其可见时必须要小心。以下代码之一将起作用:

   root.setGlassPane(newGlassPane);
   newGlassPane.setVisible(true);
 
或者:
   root.getGlassPane().setVisible(true);
   root.setGlassPane(newGlassPane);
 

参数:
glass - 要用作此 JRootPane 的玻璃窗格的 Component
抛出:
NullPointerException - 如果 glass 参数为 null

getGlassPane

public Component getGlassPane()
返回此 JRootPane 的当前玻璃窗格。

返回:
当前的玻璃窗格
另请参见:
setGlassPane(java.awt.Component)

isValidateRoot

public boolean isValidateRoot()
如果此 JRootPane 的一个后代调用 revalidate,将从此位置开始进行验证。

推迟对一个组件及其后代再次布局的请求。例如,对 revalidate 的调用被上推至 JRootPaneJScrollPane,因为两个类都重写 isValidateRoot 以返回 true。

覆盖:
JComponent 中的 isValidateRoot
返回:
true
另请参见:
JComponent.isValidateRoot()

isOptimizedDrawingEnabled

public boolean isOptimizedDrawingEnabled()
glassPanecontentPane 具有相同的边界,这意味着 JRootPane 并不对其子级平铺,应返回 false。另一方面,glassPane 通常为不可见,所以如果 glassPane 为不可见时,它会返回 true。因此,这里的返回值取决于 glassPane 的可见性。

覆盖:
JComponent 中的 isOptimizedDrawingEnabled
返回:
如果此组件的子级不重叠,则返回 true

addNotify

public void addNotify()
将本身注册为 SystemEventQueueUtils 的新的根窗格。

覆盖:
JComponent 中的 addNotify
另请参见:
JComponent.registerKeyboardAction(java.awt.event.ActionListener, java.lang.String, javax.swing.KeyStroke, int)

removeNotify

public void removeNotify()
将本身从 SystemEventQueueUtils 注销。

覆盖:
JComponent 中的 removeNotify
另请参见:
addNotify()

setDefaultButton

public void setDefaultButton(JButton defaultButton)
设置 defaultButton 属性,它确定此 JRootPane 的当前默认按钮。默认的按钮是根窗格中发生 UI 定义的激活事件(通常是 Enter 键)时将被激活的按钮,无论按钮是否成为键盘焦点(除非根窗格中另有一个组件使用此激活事件,例如一个 JTextPane)。为使默认的激活正常工作,在激活发生时该按钮必须是根窗格的一个已启用的后代。要从此根窗格移除一个默认的按钮,设置此属性为 null

参数:
defaultButton - 将成为默认按钮的 JButton
另请参见:
JButton.isDefaultButton()

getDefaultButton

public JButton getDefaultButton()
返回 defaultButton 属性的值。

返回:
当前为默认按钮的 JButton
另请参见:
setDefaultButton(javax.swing.JButton)

addImpl

protected void addImpl(Component comp,
                       Object constraints,
                       int index)
重写以便将玻璃组件的位置强行设置成零位子级。

覆盖:
Container 中的 addImpl
参数:
comp - 要增强的组件
constraints - 要遵守的约束条件
index - 索引
另请参见:
Container.add(Component), Container.add(Component, int), Container.add(Component, java.lang.Object), LayoutManager, LayoutManager2

paramString

protected String paramString()
返回此 JRootPane 的字符串表示形式。此方法仅在进行调试的时候使用,对于各个实现,所返回字符串的内容和格式可能有所不同。返回的字符串可能为空,但不可能为 null

覆盖:
JComponent 中的 paramString
返回:
JRootPane 的字符串表示形式。

getAccessibleContext

public AccessibleContext getAccessibleContext()
获取与此 JRootPane 相关联的 AccessibleContext。对于根窗格,AccessibleContext 采用 AccessibleJRootPane 的形式。必要时创建新的 AccessibleJRootPane 实例。

指定者:
接口 Accessible 中的 getAccessibleContext
覆盖:
JComponent 中的 getAccessibleContext
返回:
一个 AccessibleJRootPane,它充当此 JRootPaneAccessibleContext

JavaTM 2 Platform
Standard Ed. 6

提交错误或意见

版权所有 2008 Sun Microsystems, Inc. 保留所有权利。请遵守GNU General Public License, version 2 only