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() 通过将其连接到本机屏幕资源来使此 Container 可显示。 |
| 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) 返回是否已为此 Container 显式定义了给定焦点遍历操作的焦点遍历键集。 |
| 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-order索引。 |
| 26 |
ContainerListener[] getContainerListeners() 返回在此容器上注册的所有容器侦听器的数组。 |
| 27 |
Set<AWTKeyStroke> getFocusTraversalKeys(int id) 为此容器的给定遍历操作返回焦点遍历键集。 |
| 28 |
FocusTraversalPolicy getFocusTraversalPolicy() 返回将管理此 Container 的子项的键盘遍历的焦点遍历策略,如果此 Container 不是焦点循环根,则返回 null。 |
| 29 |
Insets getInsets() 确定此容器的 insets,表示容器边框的大小。 |
| 30 |
LayoutManager getLayout() 获取此容器的布局管理器。 |
| 31 |
<T extends EventListener> T[] getListeners(Class<T> listenerType) 返回当前在此 Container 上注册为 FooListeners 的所有对象的数组。 |
| 32 |
Dimension getMaximumSize() 返回此容器的最大尺寸。 |
| 33 |
Dimension getMinimumSize() 返回此容器的最小尺寸。 |
| 34 |
Point getMousePosition(boolean allowChildren) 如果Container在鼠标指针下方,则返回鼠标指针在该Container坐标空间中的位置,否则返回null。 |
| 35 |
Dimension getPreferredSize() 返回此容器的首选大小。 |
| 36 |
Insets insets() 已弃用。 从 JDK 1.1 版开始,由 getInsets() 取代。 |
| 37 |
void invalidate() 使容器无效。 |
| 38 |
boolean isAncestorOf(Component c) 检查组件是否包含在此容器的组件层次结构中。 |
| 39 |
boolean isFocusCycleRoot() 返回此 Container 是否是焦点遍历循环的根。 |
| 40 |
boolean isFocusCycleRoot(Container container) 返回指定的 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-order 索引。 |
| 62 |
void setFocusCycleRoot(boolean focusCycleRoot) 设置此 Container 是否是焦点遍历循环的根。 |
| 63 |
void setFocusTraversalKeys(int id, Set<? extends AWTKeyStroke> keystrokes) 为此 Container 的给定遍历操作设置焦点遍历键。 |
| 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

