|
JavaTM 2 Platform Standard Ed. 6 |
|||||||||
| 上一個類別 下一個類別 | 框架 無框架 | |||||||||
| 摘要: 巢狀 | 欄位 | 建構子 | 方法 | 詳細資訊: 欄位 | 建構子 | 方法 | |||||||||
java.lang.Objectjavax.swing.BoxLayout
public class BoxLayout
允許垂直或水平佈置多個元件的佈局管理器。這些元件將不包裹,因此舉例來說,垂直排列的元件在重新調整框架的大小時仍然被垂直排列。
|
|
用水平元件和垂直元件的不同組合巢狀多面板的作用類似於 GridBagLayout,但沒那麼複雜。該圖顯示了兩個水平排列的面板,每個面板都包含 3 個垂直排列的元件。
BoxLayout 管理器是用 axis 參數建構的,該參數指定了將進行的佈局型別。有四個選擇:
X_AXIS:從左到右水平佈置元件。
Y_AXIS:從上到下垂直佈置元件。
LINE_AXIS:根據容器的 ComponentOrientation 屬性,按照文字在一行中的排列方式佈置元件。如果容器的 ComponentOrientation 表示水平,則將元件水平放置,否則將它們垂直放置。對於水平方向,如果容器的 ComponentOrientation 表示從左到右,則元件從左到右放置,否則將它們從右到左放置。對於垂直方向,元件總是從上到下放置的。
PAGE_AXIS:根據容器的 ComponentOrientation 屬性,按照文本行在一頁中的排列方式佈置元件。如果容器的 ComponentOrientation 表示水平,則將元件垂直放置,否則將它們水平放置。對於水平方向,如果容器的 ComponentOrientation 表示從左到右,則元件從左到右放置,否則將它們從右到左放置。對於垂直方向,元件總是從上向下放置的。
對於所有方向,元件按照將它們添加到容器中的順序排列。
BoxLayout 試圖按照元件的首選寬度(對於水平佈局)或首選高度(對於垂直佈局)來排列它們。對於水平佈局,如果並不是所有的元件都具有相同的高度,則 BoxLayout 會試圖讓所有元件都具有最高元件的高度。如果對於某一特定元件而言這是不可能的,則 BoxLayout 會根據該元件的 Y 調整值對它進行垂直調整。預設情況下,元件的 Y 調整值為 0.5,這意味著元件的垂直中心應該與其他 Y 調整值為 0.5 的元件的垂直中心具有相同 Y 坐標。
同樣地,對於垂直佈局,BoxLayout 試圖讓列中的所有元件具有最寬元件的寬度。如果這樣做失敗,則 BoxLayout 會根據這些元件的 X 調整值對它進行水平調整。對於 PAGE_AXIS 佈局,基於元件的開始邊水平調整。換句話說,如果容器的 ComponentOrientation 表示從左到右,則 X 調整值為 0.0 意味著元件的左邊緣,否則它意味著元件的右邊緣。
許多程序使用 Box 類別,而不是直接使用 BoxLayout。Box 類別是使用 BoxLayout 的輕量級容器。它還提供了一些說明您很好地使用 BoxLayout 的便利方法。要獲取您想要的排列,將元件添加到多個巢狀的 box 中是一種功能強大的方法。
有關更多資訊和範例,請參閱 The Java Tutorial 中的 How to Use BoxLayout 一節。
警告:此類別的已序列化物件與以後的 Swing 版本不相容。當前序列化支持適用於短期存儲,或適用於在運行相同 Swing 版本的應用程序之間進行 RMI(Remote Method Invocation,遠端方法調用)。從 1.4 版本開始,已在 java.beans 套件中添加了支持所有 JavaBeansTM 長期存儲的功能。請參見 XMLEncoder。
Box,
ComponentOrientation,
JComponent.getAlignmentX(),
JComponent.getAlignmentY()| 欄位摘要 | |
|---|---|
static int |
LINE_AXIS
指定應該根據目標容器的 ComponentOrientation 屬性確定的文本行方向放置元件。 |
static int |
PAGE_AXIS
指定應該根據目標容器的 ComponentOrientation 屬性確定的文本行在頁面中的串流向來放置元件。 |
static int |
X_AXIS
指定元件應該從左到右放置。 |
static int |
Y_AXIS
指定元件應該從上到下放置。 |
| 建構子摘要 | |
|---|---|
BoxLayout(Container target,
int axis)
創建一個將沿給定軸放置元件的佈局管理器。 |
|
| 方法摘要 | |
|---|---|
void |
addLayoutComponent(Component comp,
Object constraints)
此類別不使用。 |
void |
addLayoutComponent(String name,
Component comp)
此類別不使用。 |
int |
getAxis()
返回用於佈局元件的軸。 |
float |
getLayoutAlignmentX(Container target)
返回容器沿 X 軸的對齊方式。 |
float |
getLayoutAlignmentY(Container target)
返回容器沿 Y 軸的對齊方式。 |
Container |
getTarget()
返回使用此佈局管理器的容器。 |
void |
invalidateLayout(Container target)
指示一個子容器已經更改其佈局相關資訊,因此應該刷新所有已快取記憶體的計算結果。 |
void |
layoutContainer(Container target)
在需要佈置指定容器時,由 AWT 調用 。 |
Dimension |
maximumLayoutSize(Container target)
返回目標容器佈置其所包含的元件時可使用的最大尺寸。 |
Dimension |
minimumLayoutSize(Container target)
返回佈置包含在指定目標容器中的元件所需的最小尺寸。 |
Dimension |
preferredLayoutSize(Container target)
在給出指定目標容器中的元件的前提下,返回此佈局的首選尺寸。 |
void |
removeLayoutComponent(Component comp)
此類別不使用。 |
| 從類別 java.lang.Object 繼承的方法 |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| 欄位詳細資訊 |
|---|
public static final int X_AXIS
public static final int Y_AXIS
public static final int LINE_AXIS
ComponentOrientation 屬性確定的文本行方向放置元件。
public static final int PAGE_AXIS
ComponentOrientation 屬性確定的文本行在頁面中的串流向來放置元件。
| 建構子詳細資訊 |
|---|
public BoxLayout(Container target,
int axis)
target - 需要佈置的容器axis - 佈置元件時使用的軸。它可以是以下值之一:BoxLayout.X_AXIS、BoxLayout.Y_AXIS、BoxLayout.LINE_AXIS 或 BoxLayout.PAGE_AXIS
AWTError - 如果 axis 的值無效| 方法詳細資訊 |
|---|
public final Container getTarget()
public final int getAxis()
BoxLayout.X_AXIS、BoxLayout.Y_AXIS、BoxLayout.LINE_AXIS 或 BoxLayout.PAGE_AXIS
public void invalidateLayout(Container target)
在 Container 上調用 invalidate 方法時,由 AWT 調用此方法。因為可以對事件執行緒非同步調用 invalidate 方法,所以可以非同步調用此方法。
LayoutManager2 中的 invalidateLayouttarget - 受影響的容器
AWTError - 如果目標容器不是指定給 BoxLayout 建構子的容器
public void addLayoutComponent(String name,
Component comp)
LayoutManager 中的 addLayoutComponentname - 元件的名稱comp - 元件public void removeLayoutComponent(Component comp)
LayoutManager 中的 removeLayoutComponentcomp - 元件
public void addLayoutComponent(Component comp,
Object constraints)
LayoutManager2 中的 addLayoutComponentcomp - 元件constraints - 約束public Dimension preferredLayoutSize(Container target)
LayoutManager 中的 preferredLayoutSizetarget - 需要佈置的容器
AWTError - 如果目標容器不是指定給 BoxLayout 建構子的容器Container,
minimumLayoutSize(java.awt.Container),
maximumLayoutSize(java.awt.Container)public Dimension minimumLayoutSize(Container target)
LayoutManager 中的 minimumLayoutSizetarget - 需要佈置的容器
AWTError - 如果目標容器不是指定給 BoxLayout 建構子的容器preferredLayoutSize(java.awt.Container),
maximumLayoutSize(java.awt.Container)public Dimension maximumLayoutSize(Container target)
LayoutManager2 中的 maximumLayoutSizetarget - 需要佈置的容器
AWTError - 如果目標容器不是指定給 BoxLayout 建構子的容器preferredLayoutSize(java.awt.Container),
minimumLayoutSize(java.awt.Container)public float getLayoutAlignmentX(Container target)
LayoutManager2 中的 getLayoutAlignmentXtarget - 容器
AWTError - 如果目標容器不是指定給 BoxLayout 建構子的容器public float getLayoutAlignmentY(Container target)
LayoutManager2 中的 getLayoutAlignmentYtarget - 容器
AWTError - 如果目標容器不是指定給 BoxLayout 建構子的容器public void layoutContainer(Container target)
LayoutManager 中的 layoutContainertarget - 要佈置的容器
AWTError - 如果目標容器不是指定給 BoxLayout 建構子的容器
|
JavaTM 2 Platform Standard Ed. 6 |
|||||||||
| 上一個類別 下一個類別 | 框架 無框架 | |||||||||
| 摘要: 巢狀 | 欄位 | 建構子 | 方法 | 詳細資訊: 欄位 | 建構子 | 方法 | |||||||||
版權所有 2008 Sun Microsystems, Inc. 保留所有權利。請遵守GNU General Public License, version 2 only。