|
JavaTM 2 Platform Standard Ed. 6 |
|||||||||
| 上一個類別 下一個類別 | 框架 無框架 | |||||||||
| 摘要: 巢狀 | 欄位 | 建構子 | 方法 | 詳細資訊: 欄位 | 建構子 | 方法 | |||||||||
java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JRootPane
public class JRootPane
該輕量級容器由 JFrame、JDialog、JWindow、JApplet 和 JInternalFrame 在後台使用。有關根窗格所提供功能的導向任務的資訊,請參閱 The Java Tutorial 中的 How to Use Root Panes 一節。
下面的圖像顯示了使用根窗格的各個類別之間的關係。

JFrame、JDialog、JWindow 和 JApplet)的顯示與它們擴展的 AWT 類別有關。這四個元件是 Swing 資源庫中僅有的重量級容器。這裡還顯示了輕量級容器 JInternalFrame。所有這五個 JFC/Swing 容器都實作 RootPaneContainer 介面,並且它們都將其操作委託給 JRootPane(頂端顯示有一個小 "handle")。
註:使用JComponent的getRootPane方法可獲取包含給定元件的JRootPane。
|
JRootPane 的結構。JRootpane 由一個 glassPane 和一個可選的 menuBar 以及一個 contentPane 組成。(JLayeredPane 負責管理 menuBar 和 contentPane。)glassPane 位於所有窗格之上,以便能夠截取鼠標移動。由於 glassPane(與 contentPane 類似)可以是一個任意的元件,也可以設置 glassPane 來進行繪製。這樣 glassPane 上的線條和圖像可涵蓋其下的窗體,不受其邊界的限制。
儘管 menuBar 元件為可選,但 layeredPane、contentPane 和 glassPane 總是存在的。試圖將它們設置為 null 將產生異常。
要將元件添加到 JRootPane(可選的選單欄除外),您可以將物件添加到 JRootPane 的 contentPane,如下所示:
rootPane.getContentPane().add(child);
可用同樣的方法設置佈局管理器、移除元件以及列出子級等。所有這些方法都是在 contentPane 上而不是 JRootPane 上調用的。
註:如果已在contentPane的預設佈局管理器是BorderLayout管理器。但是,JRootPane使用一個自定義的LayoutManager。所以,如果您希望更改已添加到JRootPane中的元件的佈局管理器,一定要確保使用如下程式碼:rootPane.getContentPane().setLayout(new BoxLayout());
JRootPane 上設置了 JMenuBar 元件,它將沿窗體的上邊緣放置。contentPane 的位置和大小將進行調整以填充剩餘的區域。(JMenuBar 和 contentPane 被添加到位於 JLayeredPane.FRAME_CONTENT_LAYER 層的 layeredPane 元件中。)
layeredPane 是 JRootPane 中所有子級的父級,既是選單的直接父級,又是添加到 contentPane 中的所有元件的祖父級。它是 JLayeredPane 的實例,提供在若干層上添加元件的能力。在處理彈出選單、對話框以及拖動時,即要求將元件置於窗格中所有其它元件之上的情況下,此功能非常有用。
glassPane 位於 JRootPane 中所有其它元件之上。這為在所有其它元件上繪圖和截取鼠標事件提供了方便,這對拖動和繪圖都非常有用。開發人員可在 glassPane 上使用 setVisible 控制 glassPane 在所有其它子級上面顯示的時間。預設情況下,glassPane 為不可見。
JRootPane 所使用的自定義 LayoutManager 可確保:
glassPane 填充了 JRootPane 的整個可查看區域(邊界 - insets)。
layeredPane 填充了 JRootPane 的整個可查看區域。(邊界 - insets)
menuBar 位於 layeredPane 的上邊緣。
contentPane 填充了整個可查看區域,減去 menuBar(如果有)。
JRootPane 視圖層次結構中的任何其它視圖均忽略。
如果您替換 JRootPane 的 LayoutManager,您將負責管理所有這些視圖。所以通常情況下,應該確保更改的是 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,設置其 glassPane、layeredPane 以及 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()
glassPane 和 contentPane 具有相同的邊界,這意味著 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 屬性重置為當前外觀對應的值。 |
| 從類別 java.lang.Object 繼承的方法 |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| 欄位詳細資訊 |
|---|
public static final int NONE
JRootPane 不應提供任何型別的 Window 裝飾。
public static final int FRAME
JRootPane 應提供適合 Frame 的裝飾。
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 應提供適合 Dialog 的裝飾以便顯示 JColorChooser。
public static final int FILE_CHOOSER_DIALOG
JRootPane 應提供適合 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
JRootPane 的 ActionMap 中替換 Action。有關更多詳細資訊,請參閱鍵綁定規範。
defaultButton@Deprecated protected javax.swing.JRootPane.DefaultAction defaultReleaseAction
JRootPane 的 ActionMap 中替換 Action。有關更多詳細資訊,請參閱鍵綁定規範。
defaultButton| 建構子詳細資訊 |
|---|
public JRootPane()
JRootPane,設置其 glassPane、layeredPane 以及 contentPane。
| 方法詳細資訊 |
|---|
public void setDoubleBuffered(boolean aFlag)
Component,並且還緩衝了它的某個祖先,則將使用該祖先緩衝區。
JComponent 中的 setDoubleBufferedaFlag - 如果為 true,則設置此元件使用雙緩衝區進行緩衝public int getWindowDecorationStyle()
JRootPane 提供的 Window 裝飾型別。
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 應提供的 Window 裝飾型別(例如,邊界、關閉 Window 的小部件、標題等)。預設不提供任何 Window 裝飾 (NONE)。
這只是一個提示,有些外觀可能不支持。這是一個綁定屬性。
windowDecorationStyle - 標識要提供的 Window 裝飾的常數。
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()
JComponent 中的 updateUIJComponent.updateUI()public String getUIClassID()
JComponent 中的 getUIClassIDJComponent.getUIClassID(),
UIDefaults.getUI(javax.swing.JComponent)protected JLayeredPane createLayeredPane()
layeredPane。預設情況下創建一個新的 JLayeredPane。
layeredPaneprotected Container createContentPane()
contentPane。預設情況下,此方法創建新的 JComponent 並將 BorderLayout 設置為它的 LayoutManager。
contentPaneprotected Component createGlassPane()
glassPane。預設情況下,此方法創建新的 JComponent,其可見性設置為 false。
glassPaneprotected 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() 取代。
JMenuBarpublic void setContentPane(Container content)
Swing 的繪製架構要求在包含層次結構中有一個不透明的 JComponent。這通常由內容窗格提供。如果要替換內容窗格,則建議用一個不透明的 JComponent 來替代。
content - 供元件內容使用的 Container
IllegalComponentStateException - (運行時異常)如果內容窗格參數為 nullpublic Container getContentPane()
Containerpublic void setLayeredPane(JLayeredPane layered)
JMenuBar。
layered - 要使用的 JLayeredPane
IllegalComponentStateException - (運行時異常)如果分層窗格參數為 nullpublic JLayeredPane getLayeredPane()
JMenuBar。
JLayeredPanepublic void setGlassPane(Component glass)
Component 設置為此根窗格的玻璃窗格。玻璃窗格通常應該是一個輕量級的、透明的元件,因為每當根窗格需要抓取輸入事件時會將它設置為可見。
更改新玻璃窗格的可見性,以比對當前玻璃窗格的可見性。其含義是,當想要替換玻璃窗格並使其可見時必須要小心。以下程式碼之一將起作用:
root.setGlassPane(newGlassPane); newGlassPane.setVisible(true);或者:
root.getGlassPane().setVisible(true); root.setGlassPane(newGlassPane);
glass - 要用作此 JRootPane 的玻璃窗格的 Component
NullPointerException - 如果 glass 參數為 nullpublic Component getGlassPane()
JRootPane 的當前玻璃窗格。
setGlassPane(java.awt.Component)public boolean isValidateRoot()
JRootPane 的一個後代調用 revalidate,將從此位置開始進行驗證。
推遲對一個元件及其後代再次佈局的請求。例如,對 revalidate 的調用被上推至 JRootPane 或 JScrollPane,因為兩個類別都覆寫 isValidateRoot 以返回 true。
JComponent 中的 isValidateRootJComponent.isValidateRoot()public boolean isOptimizedDrawingEnabled()
glassPane 和 contentPane 具有相同的邊界,這意味著 JRootPane 並不對其子級平鋪,應返回 false。另一方面,glassPane 通常為不可見,所以如果 glassPane 為不可見時,它會返回 true。因此,這裡的返回值取決於 glassPane 的可見性。
JComponent 中的 isOptimizedDrawingEnabledpublic void addNotify()
SystemEventQueueUtils 的新的根窗格。
JComponent 中的 addNotifyJComponent.registerKeyboardAction(java.awt.event.ActionListener, java.lang.String, javax.swing.KeyStroke, int)public void removeNotify()
SystemEventQueueUtils 註銷。
JComponent 中的 removeNotifyaddNotify()public void setDefaultButton(JButton defaultButton)
defaultButton 屬性,它確定此 JRootPane 的當前預設按鈕。預設的按鈕是根窗格中發生 UI 定義的啟動事件(通常是 Enter 鍵)時將被啟動的按鈕,無論按鈕是否成為鍵盤焦點(除非根窗格中另有一個元件使用此啟動事件,例如一個 JTextPane)。為使預設的啟動正常工作,在啟動發生時該按鈕必須是根窗格的一個已啟用的後代。要從此根窗格移除一個預設的按鈕,設置此屬性為 null。
defaultButton - 將成為預設按鈕的 JButtonJButton.isDefaultButton()public JButton getDefaultButton()
defaultButton 屬性的值。
JButtonsetDefaultButton(javax.swing.JButton)
protected void addImpl(Component comp,
Object constraints,
int index)
Container 中的 addImplcomp - 要增強的元件constraints - 要遵守的約束條件index - 索引Container.add(Component),
Container.add(Component, int),
Container.add(Component, java.lang.Object),
LayoutManager,
LayoutManager2protected String paramString()
JRootPane 的字元串表示形式。此方法僅在進行除錯的時候使用,對於各個實作,所返回字元串的內容和格式可能有所不同。返回的字元串可能為空,但不可能為 null。
JComponent 中的 paramStringJRootPane 的字元串表示形式。public AccessibleContext getAccessibleContext()
JRootPane 相關聯的 AccessibleContext。對於根窗格,AccessibleContext 採用 AccessibleJRootPane 的形式。必要時創建新的 AccessibleJRootPane 實例。
Accessible 中的 getAccessibleContextJComponent 中的 getAccessibleContextAccessibleJRootPane,它充當此 JRootPane 的 AccessibleContext
|
JavaTM 2 Platform Standard Ed. 6 |
|||||||||
| 上一個類別 下一個類別 | 框架 無框架 | |||||||||
| 摘要: 巢狀 | 欄位 | 建構子 | 方法 | 詳細資訊: 欄位 | 建構子 | 方法 | |||||||||
版權所有 2008 Sun Microsystems, Inc. 保留所有權利。請遵守GNU General Public License, version 2 only。