public class JRootPane extends JComponent implements Accessible
JFrame , JDialog , JWindow , JApplet和JInternalFrame 。
有关根窗格提供的功能的面向任务的信息,请参阅Java教程中的 How to Use Root Panes 。
以下图像显示了使用根窗格的类之间的关系。

JFrame , JDialog , JWindow和JApplet )被示出相对于它们扩展AWT类。
这四个组件是Swing库中唯一重量级的容器。
还示出了轻型容器JInternalFrame 。
所有这五个JFC / Swing容器都实现了RootPaneContainer接口,他们都将其操作委托给一个JRootPane (顶部有一个“句柄”)。
Note: TheJComponentmethodgetRootPanecan be used to obtain theJRootPanethat contains a given component.
JRootPane 。
A JRootpane由glassPane ,可选的menuBar和contentPane 。
( JLayeredPane管理menuBar和contentPane ) glassPane位于所有的顶部,它可以拦截鼠标移动。
由于glassPane (如contentPane )可以是任意组件,也可以设置glassPane进行绘图。
然后, glassPane上的线条和图像可以在下面的框架之上,而不受其边界的限制。
虽然menuBar组件是可选的,在layeredPane , contentPane和glassPane始终存在。 尝试将其设置为null会生成异常。
要将组件添加到JRootPane (可选菜单栏除外),您将对象添加到contentPane的JRootPane ,如下所示:
rootPane.getContentPane().add(child);
设置布局管理器,删除组件,列出子项等同样的原则。所有这些方法都在contentPane而不是在JRootPane上JRootPane 。
Note: The default layout manager for the如果在contentPaneis 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上设置了JRootPane ,则它将沿着框架的上边缘定位。
contentPane的位置和大小进行了调整,以填补剩余的面积。
( JMenuBar和contentPane被添加到layeredPane组件在JLayeredPane.FRAME_CONTENT_LAYER层。)
该layeredPane是在所有儿童的家长JRootPane -既是菜单的直接父和所有组件的祖父加入到contentPane 。 它是一个JLayeredPane的实例,它提供了在多个层中添加组件的功能。 使用菜单弹出窗口,对话框和拖动时,此功能非常有用,您需要将组件放置在窗格中所有其他组件的顶部。
glassPane位于JRootPane中所有其他组件的JRootPane 。 这提供了一个方便的地方来绘制所有其他组件,并且可以拦截鼠标事件,这对拖动和绘图都是有用的。 开发人员可以使用setVisible在glassPane时控制glassPane显示比其他孩子。 默认情况下, glassPane不可见。
自定义LayoutManager所用JRootPane确保:
glassPane填写JRootPane (边界 - 插图)的整个可见区域。 layeredPane充满整个可视区域JRootPane 。 (边界 - 插图) menuBar位于的上边缘layeredPane 。 contentPane填写整个可见区域,减去menuBar (如果存在)。 JRootPane视图层次结构中的任何其他视图将被忽略。
如果您更换LayoutManager的JRootPane ,那么您有责任管理所有这些视图。 所以通常你会想确保你更改contentPane而不是JRootPane本身的布局管理器!
Swing的绘画架构需要一个不透明的JComponent存在于所有其他组件之上的包含层次结构中。 这通常通过内容窗格提供。 如果更换内容窗格,建议你做内容窗格不透明的方式setOpaque(true) 。 另外,如果内容窗格覆盖paintComponent ,则需要在paintComponent中完全填充不透明颜色的paintComponent 。
警告: Swing不是线程安全的。 有关更多信息,请参阅Swing's Threading Policy 。
警告:此类的序列化对象与将来的Swing版本不兼容。 当前的序列化支持适用于运行相同版本的Swing的应用程序之间的短期存储或RMI。 从1.4开始,对所有JavaBeans的长期存储的支持已被添加到java.beans包中。 请参阅XMLEncoder 。
JLayeredPane , JMenuBar , JWindow , JFrame , JDialog , JApplet , JInternalFrame , JComponent , BoxLayout , Mixing Heavy and Light Components
| Modifier and Type | Class and Description |
|---|---|
protected class |
JRootPane.AccessibleJRootPane
这个类实现了可访问性支持
JRootPane类。
|
protected class |
JRootPane.RootLayout
一个自定义布局管理器,负责分层面,玻璃面和菜单栏的布局。
|
JComponent.AccessibleJComponentContainer.AccessibleAWTContainerComponent.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy| Modifier and Type | Field and Description |
|---|---|
static int |
COLOR_CHOOSER_DIALOG
用于windowDecorationStyle属性的常量。
|
protected Container |
contentPane
内容窗格。
|
protected JButton |
defaultButton
当窗格具有焦点并且出现特定于UI的操作(如按
Enter键)时,该按钮将被激活。
|
protected javax.swing.JRootPane.DefaultAction |
defaultPressAction
已弃用
从Java 2平台v1.3开始。
|
protected javax.swing.JRootPane.DefaultAction |
defaultReleaseAction
已弃用
从Java 2平台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属性的常量。
|
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWaccessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH| Constructor and Description |
|---|
JRootPane()
创建一个
JRootPane ,设立了
glassPane ,
layeredPane和
contentPane 。
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
addImpl(Component comp, Object constraints, int index)
覆盖以执行玻璃部件的位置作为零子。
|
void |
addNotify()
通知此组件它现在有一个父组件。
|
protected Container |
createContentPane()
由构造函数调用方法创建默认的
contentPane 。
|
protected Component |
createGlassPane()
由构造函数调用方法创建默认的
glassPane 。
|
protected JLayeredPane |
createLayeredPane()
由构造函数调用方法创建默认的
layeredPane 。
|
protected LayoutManager |
createRootLayout()
由构造函数调用方法创建默认的
layoutManager 。
|
AccessibleContext |
getAccessibleContext()
获取
AccessibleContext与此相关
JRootPane 。
|
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被提供。
|
boolean |
isOptimizedDrawingEnabled()
glassPane和
contentPane具有相同的界限,这意味着
JRootPane不会
JRootPane的孩子,这应该返回false。
|
boolean |
isValidateRoot()
如果这个JRootPane的
JRootPane打电话
revalidate ,从这里下来验证。
|
protected String |
paramString()
返回此
JRootPane的字符串表示
JRootPane 。
|
void |
removeNotify()
通知此组件它不再具有父组件。
|
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应该提供的窗口装饰类型(如边框,关闭窗口的小部件,标题...)。
|
void |
updateUI()
将UI属性重置为当前外观的值。
|
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, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isPaintingForPrint, isPaintingOrigin, 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, updateadd, 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, transferFocusDownCycle, validate, validateTreeaction, 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, 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, transferFocusBackward, transferFocusUpCyclepublic static final int NONE
JRootPane不应提供任何类型的窗口装饰。
public static final int FRAME
JRootPane应提供适用于框架的装饰。
public static final int PLAIN_DIALOG
JRootPane应提供适合于Dialog的装饰。
public static final int INFORMATION_DIALOG
JRootPane应提供适用于显示信息性消息的Dialog的装饰。
public static final int ERROR_DIALOG
JRootPane应提供适用于显示错误消息的Dialog的装饰。
public static final int COLOR_CHOOSER_DIALOG
JRootPane应提供适用于显示JColorChooser的Dialog的JColorChooser 。
public static final int FILE_CHOOSER_DIALOG
JRootPane应提供适用于显示JFileChooser的Dialog的JFileChooser 。
public static final int QUESTION_DIALOG
JRootPane应提供适合用于向用户呈现问题的Dialog的装饰。
public static final int WARNING_DIALOG
JRootPane应提供适用于显示警告消息的Dialog的装饰。
protected JMenuBar menuBar
protected Container contentPane
protected JLayeredPane layeredPane
protected Component glassPane
protected JButton defaultButton
@Deprecated protected javax.swing.JRootPane.DefaultAction defaultPressAction
Action在JRootPane的ActionMap 。
有关详细信息,请参阅密钥绑定规范。
defaultButton
@Deprecated protected javax.swing.JRootPane.DefaultAction defaultReleaseAction
Action在JRootPane的ActionMap 。
有关详细信息,请参阅密钥绑定规范。
defaultButton
public void setDoubleBuffered(boolean aFlag)
Component被缓冲,并且其祖先之一也被缓存,那么将使用祖先缓冲区。
setDoubleBuffered在
JComponent
aFlag - 如果为true,请将此组件设置为双缓冲
public int getWindowDecorationStyle()
JRootPane被提供。
NONE ,
FRAME ,
PLAIN_DIALOG ,
INFORMATION_DIALOG ,
ERROR_DIALOG ,
COLOR_CHOOSER_DIALOG ,
FILE_CHOOSER_DIALOG ,
QUESTION_DIALOG或
WARNING_DIALOG 。
setWindowDecorationStyle(int)
public void setWindowDecorationStyle(int windowDecorationStyle)
JRootPane应提供的窗口装饰类型(如边框,关闭窗口的小部件,标题...)。
默认是不提供窗口装饰( NONE )。
这只是一个提示,一些看起来和感觉可能不支持这一点。 这是一个绑定属性。
windowDecorationStyle - 常规识别提供的窗口装饰。
IllegalArgumentException -如果
style不是一个:
NONE ,
FRAME ,
PLAIN_DIALOG ,
INFORMATION_DIALOG ,
ERROR_DIALOG ,
COLOR_CHOOSER_DIALOG ,
FILE_CHOOSER_DIALOG ,
QUESTION_DIALOG ,或
WARNING_DIALOG 。
JDialog.setDefaultLookAndFeelDecorated(boolean) ,
JFrame.setDefaultLookAndFeelDecorated(boolean) ,
LookAndFeel.getSupportsWindowDecorations()
public RootPaneUI getUI()
LabelUI对象
public void setUI(RootPaneUI ui)
ui -
LabelUI L&F对象
UIDefaults.getUI(javax.swing.JComponent)
public void updateUI()
updateUI在
JComponent
JComponent.updateUI()
public String getUIClassID()
getUIClassID在
JComponent
JComponent.getUIClassID() ,
UIDefaults.getUI(javax.swing.JComponent)
protected JLayeredPane createLayeredPane()
layeredPane 。
Bt默认它创建一个新的JLayeredPane 。
layeredPane
protected Container createContentPane()
contentPane 。
默认情况下,此方法创建一个新的JComponent添加一个BorderLayout作为其LayoutManager 。
contentPane
protected Component createGlassPane()
glassPane 。
默认情况下,此方法创建一个新的JComponent ,其可见性设置为false。
glassPane
protected LayoutManager createRootLayout()
layoutManager 。
layoutManager 。
public void setJMenuBar(JMenuBar menu)
menu -
JMenuBar加
@Deprecated public void setMenuBar(JMenuBar menu)
setJMenuBar(JMenuBar menu) 。
menu - 加
JMenuBar 。
public JMenuBar getJMenuBar()
JMenuBar
@Deprecated public JMenuBar getMenuBar()
getJMenuBar() 。
JMenuBar
public void setContentPane(Container content)
Swing的绘画架构需要在JComponent中不透明的JComponent。 这通常由内容窗格提供。 如果更换内容窗格,建议将其替换为不透明的JComponent 。
content -在
Container要使用组件的内容
IllegalComponentStateException - (运行时异常),如果内容窗格参数是
null
public Container getContentPane()
Container保持所述组件的内容
public void setLayeredPane(JLayeredPane layered)
JMenuBar 。
layered -
JLayeredPane使用
IllegalComponentStateException - (运行时异常)如果分层窗格参数为
null
public JLayeredPane getLayeredPane()
JMenuBar 。
JLayeredPane使用的
JLayeredPane
public void setGlassPane(Component glass)
Component成为这根窗格玻璃板。
玻璃窗格通常应该是一个轻量级的透明组件,因为当根窗格需要抓取输入事件时,它将被显示。
新的玻璃窗格的可见性已更改为与当前玻璃窗格相匹配。 这意味着,当您要更换玻璃窗格并使其可见时,必须小心。 以下任何一种都可以工作:
root.setGlassPane(newGlassPane);
newGlassPane.setVisible(true);
要么:
root.getGlassPane().setVisible(true);
root.setGlassPane(newGlassPane);
glass -
Component用作这个
JRootPane
NullPointerException - 如果
glass参数是
null
public Component getGlassPane()
JRootPane的当前玻璃窗格。
setGlassPane(java.awt.Component)
public boolean isValidateRoot()
JRootPane打电话revalidate ,从这里下来验证。
延迟请求再次布置组件及其后代。 例如,调用revalidate ,被推到JRootPane或JScrollPane ,因为这两个类覆盖isValidateRoot以返回true。
isValidateRoot在
JComponent
JComponent.isValidateRoot() ,
Container.isValidateRoot()
public boolean isOptimizedDrawingEnabled()
glassPane和contentPane具有相同的界限,这意味着JRootPane不会JRootPane ,这应该返回false。
另一方面, glassPane通常不可见,因此如果glassPane不可见,则可以返回true。
因此,这里的返回值取决于glassPane的glassPane 。
isOptimizedDrawingEnabled在
JComponent
public void addNotify()
KeyboardAction事件侦听器设置。
该方法在内部被工具包调用,不应该被程序直接调用。
public void removeNotify()
KeyboardAction 。
该方法在内部被工具包调用,不应该被程序直接调用。
public void setDefaultButton(JButton defaultButton)
defaultButton属性,它确定这个当前的默认按钮JRootPane 。
默认按钮是在根界面中发生UI定义的激活事件(通常为Enter键)时将激活的按钮,无论按钮是否具有键盘焦点(除非根窗格中有另一个组件消耗激活事件,如JTextPane )。
要使默认激活工作,当激活发生时,该按钮必须是根窗格的启用后代。
要从此根窗格中删除默认按钮,请将此属性设置为null 。
defaultButton -
JButton哪个是默认按钮
JButton.isDefaultButton()
public JButton getDefaultButton()
defaultButton属性的值。
JButton是目前的默认按钮
setDefaultButton(javax.swing.JButton)
protected void addImpl(Component comp, Object constraints, int index)
addImpl在
Container
comp - 要增强的组件
constraints - 要遵守的约束
index - 指数
Container.add(Component) , Container.add(Component, int) , Container.add(Component, java.lang.Object) , Container.invalidate() , LayoutManager , LayoutManager2
protected String paramString()
JRootPane的字符串表示JRootPane 。
该方法仅用于调试目的,并且返回的字符串的内容和格式可能因实现而异。
返回的字符串可能为空,但可能不是null 。
paramString在
JComponent
JRootPane的字符串表示
JRootPane 。
public AccessibleContext getAccessibleContext()
AccessibleContext与此相关JRootPane 。
为根窗格,所述AccessibleContext需要一个的形式AccessibleJRootPane 。
如有必要,将创建一个新的AccessibleJRootPane实例。
getAccessibleContext在界面
Accessible
getAccessibleContext在
Component
AccessibleJRootPane作为这个
AccessibleContext的
JRootPane
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.