Swing - 容器類



介紹

Container 類是 AWT 容器的超類。容器物件可以包含其他 AWT 元件。

類宣告

以下是 java.awt.Container 類的宣告:

public class Container
   extends Component

類建構函式

序號 建構函式 & 描述
1

Container()

建立新的容器。

類方法

序號 方法 & 描述
1

Component add(Component comp)

將指定的元件追加到此容器的末尾。

2

Component add(Component comp, int index)

在給定位置將指定的元件新增到此容器。

3

void add(Component comp, Object constraints)

將指定的元件新增到此容器的末尾。

4

void add(Component comp, Object constraints, int index)

使用指定的約束在指定索引處將指定的元件新增到此容器。

5

Component add(String name, Component comp)

將指定的元件新增到此容器。

6

void addContainerListener(ContainerListener l)

新增指定的容器監聽器以接收來自此容器的容器事件。

7

protected void addImpl(Component comp, Object constraints, int index)

在指定索引處將指定的元件新增到此容器。

8

void addNotify()

透過將其連線到本機螢幕資源使此容器可顯示。

9

void addPropertyChangeListener(PropertyChangeListener listener)

將 PropertyChangeListener 新增到監聽器列表。

10

void addPropertyChangeListener(String propertyName, PropertyChangeListener listener)

為特定屬性將 PropertyChangeListener 新增到監聽器列表。

11

void applyComponentOrientation(ComponentOrientation o)

設定此容器及其包含的所有元件的 ComponentOrientation 屬性。

12

boolean areFocusTraversalKeysSet(int id)

返回是否已為此容器明確定義了給定焦點遍歷操作的焦點遍歷鍵集。

13

int countComponents()

已棄用。從 JDK 版本 1.1 開始,已替換為 getComponentCount()。

14

void deliverEvent(Event e)

已棄用。從 JDK 版本 1.1 開始,已替換為 dispatchEvent(AWTEvent e)

15

void doLayout()

導致此容器佈置其元件。

16

Component findComponentAt(int x, int y)

找到包含指定位置的可見子元件。

17

Component findComponentAt(Point p)

找到包含指定點的可見子元件。

18

float getAlignmentX()

返回沿 x 軸的對齊方式。

19

float getAlignmentY()

返回沿 y 軸的對齊方式。

20

Component getComponent(int n)

獲取此容器中的第 n 個元件。

21

Component getComponentAt(int x, int y)

找到包含 x,y 位置的元件。

22

Component getComponentAt(Point p)

獲取包含指定點的元件。

23

int getComponentCount()

獲取此面板中的元件數。

24

Component[] getComponents()

獲取此容器中的所有元件。

25

int getComponentZOrder(Component comp)

返回元件在容器內的 z 順序 索引。

26

ContainerListener[] getContainerListeners()

返回在此容器上註冊的所有容器監聽器的陣列。

27

Set<AWTKeyStroke> getFocusTraversalKeys(int id)

返回此容器的給定遍歷操作的焦點遍歷鍵集。

28

FocusTraversalPolicy getFocusTraversalPolicy()

返回將管理此容器子級鍵盤遍歷的焦點遍歷策略,如果此容器不是焦點迴圈根,則返回 null。

29

Insets getInsets()

確定此容器的插入,指示容器邊框的大小。

30

LayoutManager getLayout()

獲取此容器的佈局管理器。

31

<T extends EventListener> T[] getListeners(Class<T> listenerType)

返回當前在此容器上註冊為 FooListeners 的所有物件的陣列。

32

Dimension getMaximumSize()

返回此容器的最大大小。

33

Dimension getMinimumSize()

返回此容器的最小大小。

34

Point getMousePosition(boolean allowChildren)

如果容器位於滑鼠指標下方,則返回此容器座標空間中滑鼠指標的位置,否則返回 null。

35

Dimension getPreferredSize()

返回此容器的首選大小。

36

Insets insets()

已棄用。從 JDK 版本 1.1 開始,已替換為 getInsets()。

37

void invalidate()

使容器無效。

38

boolean isAncestorOf(Component c)

檢查元件是否包含在此容器的元件層次結構中。

39

boolean isFocusCycleRoot()

返回此容器是否為焦點遍歷迴圈的根。

40

boolean isFocusCycleRoot(Container container)

返回指定的容器是否為此容器的焦點遍歷迴圈的焦點迴圈根。

41

boolean isFocusTraversalPolicyProvider()

返回此容器是否提供焦點遍歷策略。

42

boolean isFocusTraversalPolicySet()

返回是否已為此容器明確設定焦點遍歷策略。

43

void layout()

已棄用。從 JDK 版本 1.1 開始,已替換為 doLayout()。

44

void list(PrintStream out, int indent)

將此容器的列表列印到指定的輸出流。

45

void list(PrintWriter out, int indent)

從指定的縮排開始,將列表列印到指定的列印寫入器。

46

Component locate(int x, int y)

已棄用。從 JDK 版本 1.1 開始,已替換為 getComponentAt(int, int)。

47

Dimension minimumSize()

已棄用。從 JDK 版本 1.1 開始,已替換為 getMinimumSize()。

48

void paint(Graphics g)

繪製容器。

49

void paintComponents(Graphics g)

繪製此容器中的每個元件。

50

protected String paramString()

返回表示此容器狀態的字串。

51

Dimension preferredSize()

已棄用。從 JDK 版本 1.1 開始,已替換為 getPreferredSize()。

52

void print(Graphics g)

列印容器。

53

void printComponents(Graphics g)

列印此容器中的每個元件。

54

protected void processContainerEvent(ContainerEvent e)

透過將發生的容器事件分派到任何已註冊的 ContainerListener 物件,來處理在此容器上發生的容器事件。

55

protected void processEvent(AWTEvent e)

處理此容器上的事件。

56

void remove(Component comp)

從此容器中刪除指定的元件。

57

void remove(int index)

從此容器中刪除由索引指定的元件。

58

void removeAll()

從此容器中刪除所有元件。

59

void removeContainerListener(ContainerListener l)

刪除指定的容器監聽器,以便它不再接收來自此容器的容器事件。

60

void removeNotify()

透過刪除其與本機螢幕資源的連線,使此容器不可顯示。

61

void setComponentZOrder(Component comp, int index)

將指定的元件移動到容器中指定的 z 順序 索引。

62

void setFocusCycleRoot(boolean focusCycleRoot)

設定此容器是否為焦點遍歷迴圈的根。

63

void setFocusTraversalKeys(int id, Set<? extends AWTKeyStroke> keystrokes)

設定此容器的給定遍歷操作的焦點遍歷鍵。

64

void setFocusTraversalPolicy(FocusTraversalPolicy policy)

如果此容器是焦點迴圈根,則設定將管理此容器子級鍵盤遍歷的焦點遍歷策略。

65

void setFocusTraversalPolicyProvider(boolean provider)

設定是否將使用此容器來提供焦點遍歷策略。

66

void setFont(Font f)

設定此容器的字型。

67

void setLayout(LayoutManager mgr)

設定此容器的佈局管理器。

68

void transferFocusBackward()

將焦點轉移到上一個元件,就像此元件是焦點擁有者一樣。

69

void transferFocusDownCycle()

將焦點向下轉移一個焦點遍歷迴圈。

70

void update(Graphics g)

更新容器。

71

void validate()

驗證此容器及其所有子元件。

72

protected void validateTree()

遞迴下降容器樹並重新計算標記為需要它的任何子樹的佈局(標記為無效的那些)。

繼承的方法

此類繼承自以下類的方法:

  • java.awt.Component
  • java.lang.Object
swing_controls.htm
廣告