AWT Component 组件类

简介

Component 是 AWT 非菜单用户界面控件的抽象基类。组件表示具有图形表示的对象。

类声明

以下是 java.awt.Component 类的声明:

public abstract class Component
    extends Object
        implements ImageObserver, MenuContainer, Serializable

字段

以下是 java.awt.Component 类的字段:

  • static float BOTTOM_ALIGNMENT -- getAlignmentY 的易用常量。

  • static float CENTER_ALIGNMENT -- getAlignmentY 和 getAlignmentX 的易用常量。

  • static float LEFT_ALIGNMENT -- getAlignmentX 的易用常量。

  • static float RIGHT_ALIGNMENT -- getAlignmentX 的易用常量。

  • static float TOP_ALIGNMENT -- getAlignmentY() 的易用常量。

类构造函数

S.N.构造函数 &描述
1

protected Component()

这将创建一个新的组件。

类方法

S.N.方法和描述
1

boolean action(Event evt, Object what)

已弃用。从 JDK 1.1 版开始,应将此组件注册为触发操作事件的组件上的 ActionListener。

2

void add(PopupMenu popup)

将指定的弹出菜单添加到组件。

3

void addComponentListener(ComponentListener l)

添加指定的组件侦听器以从此组件接收组件事件。

4

void addFocusListener(FocusListener l)

添加指定的焦点侦听器以在此组件获得输入时从此组件接收焦点事件焦点。

5

void addHierarchyBoundsListener(HierarchyBoundsListener l)

添加指定的层次结构边界侦听器,以便当此容器所属的层次结构发生变化时从此组件接收层次结构边界事件。

6

void addHierarchyListener(HierarchyListener l)

添加指定的层次结构侦听器,以便当此容器所属的层次结构发生变化时从此组件接收层次结构更改事件。

7

void addInputMethodListener(InputMethodListener l)

添加指定的输入法侦听器,以便从此组件接收输入法事件组件。

8

void addKeyListener(KeyListener l)

添加指定的按键监听器,以接收来自此组件的按键事件。

9

void addMouseListener(MouseListener l)

添加指定的鼠标监听器,以接收来自此组件的鼠标事件。

10

void addMouseMotionListener(MouseMotionListener l)

添加指定的鼠标动作监听器,以接收来自此组件的鼠标动作事件。

11

void addMouseWheelListener(MouseWheelListener l)

添加指定的鼠标滚轮监听器以接收来自此组件的鼠标滚轮事件。

12

void addNotify()

通过将此组件连接到本机屏幕资源,使其可显示。

13

void addPropertyChangeListener(PropertyChangeListener listener)

将 PropertyChangeListener 添加到侦听器列表。

14

void addProperty ChangeListener(String propertyName, Property ChangeListener listener)

将 PropertyChangeListener 添加到特定属性的侦听器列表。

15

void applyComponentOrientation(ComponentOrientation orientation)

设置此组件及其所包含的所有组件的 ComponentOrientation 属性

16

boolean areFocusTraversalKeysSet(int id)

返回是否已为此组件明确定义给定焦点遍历操作的焦点遍历键集。

17

int checkImage(Image image, ImageObserver observer)

返回指定图像的屏幕表示的构造状态。

18

int checkImage(Image image,int width,int height, ImageObserver observer)

返回指定图像的屏幕表示的构造状态图像。

19

boolean contains(int x,int y)

检查此组件是否"包含"指定点,其中 x 和 y 定义为相对于此组件的坐标系。

20

boolean contains(Point p)

检查此组件是否"包含"指定点,其中该点的 x 和 y 坐标定义为相对于此组件的坐标系。

21

Image createImage(ImageProducer production)

根据指定图像创建图像生产者。

22

Image createImage(int width,int height)

创建一个屏幕外可绘制图像,用于双缓冲。

23

VolatileImage createVolatileImage(int width,int height)

创建一个易失性屏幕外可绘制图像,用于双缓冲。

24

VolatileImage createVolatileImage(int width,int height, ImageCapabilities caps)

创建一个易失性屏幕外可绘制图像,具有给定的功能。

25

void deliverEvent(Event e)

已弃用。从 JDK 1.1 版开始,由 dispatchEvent(AWTEvent e) 取代。

26

void disable()

已弃用。从 JDK 1.1 版开始,由 setEnabled(boolean) 取代。

27

protected void disableEvents(long eventsToDisable)

禁止将指定事件掩码参数定义的事件传递给此组件。

28

void dispatchEvent(AWTEvent e)

将事件分派给此组件或其子组件之一。

29

void doLayout()

提示布局管理器布局此组件。

30

void enable()

已弃用。从 JDK 1.1 版开始,由 setEnabled(boolean) 取代。

31

void enable(boolean b)

已弃用。从 JDK 1.1 版开始,由 setEnabled(boolean) 取代。

32

protected void enableEvents(long eventsToEnable)

启用由指定事件掩码参数定义的事件以传递到此组件。

33

void enableInputMethods(boolean enable)

启用或禁用此组件的输入法支持。

34

protected void firePropertyChange(String propertyName, boolean oldValue, boolean newValue)

支持报告布尔值的绑定属性更改属性。

35

void firePropertyChange(String propertyName, byte oldValue, byte newValue)

报告绑定属性更改。

36

void firePropertyChange(String propertyName, char oldValue, char newValue)

报告绑定属性更改。

37

void firePropertyChange(String propertyName, double oldValue, double newValue)

报告绑定属性更改。

38

void firePropertyChange(String propertyName, float oldValue, float newValue)

报告绑定属性更改。

39

void firePropertyChange(String propertyName, long oldValue, long newValue)

报告绑定属性更改。

40

protected void firePropertyChange(String propertyName, Object oldValue, Object newValue)

支持报告 Object 属性的绑定属性更改。

41

void firePropertyChange(String propertyName, short oldValue, short newValue)

报告绑定属性更改。

42

AccessibleContext getAccessibleContext()

获取与此组件关联的 AccessibleContext。

43

float getAlignmentX()

返回沿 x 轴的对齐方式。

44

float getAlignmentY()

返回沿 y 轴的对齐方式。

45

Color getBackground()

获取此组件的背景颜色。

46

int getBaseline(int width,int height)

返回基线。

47

Component.BaselineResizeBehavior getBaselineResizeBehavior()

返回一个枚举,指示组件的基线如何随着大小的变化而变化。

48

Rectangle getBounds()

以 Rectangle 对象的形式获取此组件的边界。

49

Rectangle getBounds(Rectangle rv)

将此组件的边界存储到返回值 rv 中并返回rv。

50

ColorModel getColorModel()

获取用于在输出设备上显示组件的 ColorModel 实例。

51

Component getComponentAt(int x,int y)

确定此组件或其直接子组件之一是否包含 (x, y) 位置,如果是,则返回包含的组件。

52

Component getComponentAt(Point p)

返回包含指定点的组件或子组件。

53

ComponentListener[] getComponentListeners()

返回在此组件上注册的所有组件侦听器的数组。

54

ComponentOrientation getComponentOrientation()

检索用于排序此组件内的元素或文本的语言敏感方向。

55

Cursor getCursor()

获取组件中设置的光标。

56

DropTarget getDropTarget()

获取与此组件关联的 DropTarget组件。

57

Container getFocusCycleRootAncestor()

返回此组件的焦点遍历循环的焦点循环根容器。

58

FocusListener[] getFocusListeners()

返回在此组件上注册的所有焦点监听器的数组。

59

Set<AWTKeyStroke> getFocusTraversalKeys(int id)

返回此组件的给定遍历操作的焦点遍历键集。

60

boolean getFocusTraversalKeysEnabled()

返回此组件是否启用了焦点遍历键。

61

Font getFont()

获取此组件的字体。

62

FontMetrics getFontMetrics(Font font)

获取指定字体的字体度量。

63

Color getForeground()

获取此组件的前景色。

64

Graphics getGraphics()

为此组件创建图形上下文。

65

GraphicsConfiguration getGraphicsConfiguration()

获取与此组件关联的 GraphicsConfiguration。

66

int getHeight()

返回此组件的当前高度组件。

67

HierarchyBoundsListener[] getHierarchyBoundsListeners()

返回此组件上注册的所有层次结构边界侦听器的数组。

68

HierarchyListener[] getHierarchyListeners()

返回此组件上注册的所有层次结构侦听器的数组。

69

boolean getIgnoreRepaint()

70

InputContext getInputContext()

获取此组件用于处理与输入方法通信时的输入上下文在此组件中输入了文本。

71

InputMethodListener[] getInputMethodListeners()
返回在此组件上注册的所有输入法监听器的数组。

72

InputMethodRequests getInputMethodRequests()

获取支持此组件输入法请求的输入法请求处理程序。

73

KeyListener[] getKeyListeners()

返回在此组件上注册的所有按键监听器的数组。

74

<T extends事件监听器> T[] getListeners(Class<T> listenerType)

返回当前在此组件上注册为 FooListeners 的所有对象的数组。

75

Locale getLocale()

获取此组件的语言环境。

76

Point getLocation()

以指定组件左上角的点的形式获取此组件的位置。

77

Point getLocation(Point rv)

将此组件的 x,y 原点存储到返回值 rv 中并返回rv。

78

Point getLocationOnScreen()

以点的形式获取此组件在屏幕坐标空间中的位置,该点指定组件的左上角。

79

Dimension getMaximumSize()

获取此组件的最大尺寸。

80

Dimension getMinimumSize()

获取此组件的最小尺寸。

81

MouseListener[] getMouseListeners()

返回一个此组件上注册的所有鼠标侦听器的数组。

82

MouseMotionListener[] getMouseMotionListeners()

返回此组件上注册的所有鼠标移动侦听器的数组。

83

Point getMousePosition()

如果组件位于鼠标指针正下方,则返回鼠标指针在此组件的坐标空间中的位置,否则返回 null。

84MouseWheelListener[] getMouseWheelListeners()
返回此组件上注册的所有鼠标滚轮侦听器的数组组件。
85

String getName()

获取组件的名称。

86

Container getParent()

获取此组件的父级。

87

java.awt.peer.ComponentPeer getPeer() 已弃用。从 JDK 1.1 版开始,程序不应直接操作对等体;由布尔值 isDisplayable() 替换。

88

Dimension getPreferredSize()

获取此组件的首选大小。

89

PropertyChangeListener[] getPropertyChangeListeners()

返回在此组件上注册的所有属性更改监听器的数组。

90

Property ChangeListener[] getProperty ChangeListeners (String propertyName)

返回与命名属性关联的所有监听器的数组。

91

Dimension getSize()

以 Dimension 对象的形式返回此组件的大小。

92

Dimension getSize(Dimension rv)将此组件的宽度/高度存储返回值 rv 中并返回 rv。

93

Toolkit getToolkit()

获取此组件的工具包。

94

Object getTreeLock()

获取此组件的锁定对象(拥有线程同步监视器的对象)

用于 AWT 组件树和布局操作。

95

int getWidth()

返回此组件的当前宽度。

96

int getX()

返回组件原点的当前 x 坐标。

97

int getY()

返回组件原点的当前 y 坐标。

98

boolean gotFocus(Event evt, Object what)

已弃用。从 JDK 1.1 版开始,由 processFocusEvent(FocusEvent) 取代

99

boolean handleEvent(Event evt)

已弃用。从 JDK 1.1 版开始,由 processEvent(AWTEvent) 取代。

100

boolean hasFocus()

如果此组件是焦点所有者,则返回 true。

101

void hide()

已弃用。从 JDK 1.1 版开始,由 setVisible(boolean) 取代。

102

boolean imageUpdate(Image img,int infoflags,int x,int y,int w,int h)

当图像发生变化时重新绘制组件。

103

boolean inside(int x,int y)

已弃用。从 JDK 1.1 版开始,由 contains(int, int) 取代。

104

void invalidate()

使此组件无效。

105

boolean isBackgroundSet()

返回是否已为此组件明确设置背景颜色。

106

boolean isCursorSet()

返回是否已为此组件明确设置光标。

107

boolean isDisplayable()

确定此组件是否可显示。

108

boolean isDoubleBuffered()

如果此组件被绘制到屏幕外图像(缓冲区)

,该图像稍后会复制到屏幕上,则返回 true。

109

boolean isEnabled()

确定此组件是否已启用。

110

boolean isFocusable()

返回此组件是否可以聚焦。

111

boolean isFocusCycleRoot(Container容器)

返回指定的容器是否是此组件的焦点遍历循环的焦点循环根。

112

boolean isFocusOwner()

如果此组件是焦点所有者,则返回 true。

113

boolean isFocusTraversable()

已弃用。从 1.4 开始,由 isFocusable() 取代。

114

boolean isFontSet()

返回是否已为此组件明确设置字体。

115

boolean isForegroundSet()

返回是否已为此组件明确设置前景色。

116

boolean isLightweight()

轻量级组件没有原生工具包对等体。

117

boolean isMaximumSizeSet()

如果最大大小已设置为非空值,则返回 true,否则返回 false。

118

boolean isMinimumSizeSet()

返回 setMinimumSize 是否已使用非空值调用。

119

boolean isOpaque()

如果此组件完全不透明,则返回 true,否则返回 false默认。

120

boolean isPreferredSizeSet()

如果首选大小已设置为非空值,则返回 true,否则返回 false。

121

boolean isShowing()

确定此组件是否显示在屏幕上。

122

boolean isValid()

确定此组件是否有效。

123

boolean isVisible()

确定此组件在其父级可见时是否可见可见。

124

boolean keyDown(Event evt,int key)

已弃用。从 JDK 1.1 版开始,由 processKeyEvent(KeyEvent) 取代。

125

boolean keyUp(Event evt,int key)

已弃用。从 JDK 1.1 版开始,由 processKeyEvent(KeyEvent) 取代。

126

void layout()

已弃用。从 JDK 1.1 版开始,由 doLayout() 取代。

127

void list()

将此组件的列表打印到标准系统输出流 System.out。

128

void list(PrintStream out)

将此组件的列表打印到指定的输出流。

129

void list(PrintStream out,int indent)

从指定的缩进开始,将列表打印到指定的打印流。

130

void list(PrintWriter out)

将列表打印到指定的打印编写器。

131

void list(PrintWriter out,int indent)

从指定的缩进处开始将列表打印到指定的打印编写器。

132

Componentlocate(intx,inty)

已弃用。从 JDK 1.1 版开始,由 getComponentAt(int,int) 取代。

133

Pointlocation()

已弃用。从 JDK 1.1 版开始,由 getLocation() 取代。

134

boolean lostFocus(Event evt, Object what)

已弃用。从 JDK 1.1 版开始,由 processFocusEvent(FocusEvent) 取代。

135

boolean mouseDown(Event evt,int x,int y)

已弃用。从 JDK 1.1 版开始,由 processMouseEvent(MouseEvent) 取代。

136

boolean mouseDrag(Event evt,int x,int y)

已弃用。从 JDK 1.1 版开始,由 processMouseMotionEvent(MouseEvent) 取代。

137

boolean mouseEnter(Event evt,int x,int y)

已弃用。从 JDK 1.1 版开始,由 processMouseEvent(MouseEvent) 取代。

138

boolean mouseExit(Event evt,int x,int y)

已弃用。从 JDK 1.1 版开始,由 processMouseEvent(MouseEvent) 取代。

139

boolean mouseMove(Event evt,int x,int y)

已弃用。从 JDK 1.1 版开始,由 processMouseMotionEvent(MouseEvent) 取代。

140

boolean mouseUp(Event evt,int x,int y)

已弃用。从 JDK 1.1 版开始,由 processMouseEvent(MouseEvent) 取代。

141

void move(int x,int y)

已弃用。从 JDK 1.1 版开始,由 setLocation(int, int) 取代。

142

void nextFocus()

已弃用。从 JDK 1.1 版开始,由 transferFocus() 取代。

143

void paint(Graphics g)

绘制此组件。

144

void paintAll(Graphics g)

绘制此组件及其所有子组件。

145

boolean postEvent(Event e)

已弃用。从 JDK 1.1 版开始,由 dispatchEvent(AWTEvent) 取代。

146

boolean prepareImage(Image image,int width,int height, ImageObserver observer)

准备一个图像,以指定的宽度和高度在此组件上呈现。

147

void print(Graphics g)

打印此组件。

148

void printAll(Graphics g)

打印此组件及其所有子组件。

149

protectedvoid processComponentEvent(ComponentEvent e)

通过将发生在此组件上的组件事件分派给任何已注册的 ComponentListener 对象来处理它们。

150

protected void processEvent(AWTEvent e)

通过将发生在此组件上的事件分派给任何已注册的 FocusListener 对象来处理它们。

151

protected void processFocusEvent(FocusEvent e)

通过将发生在此组件上的焦点事件分派给任何已注册的 FocusListener 对象来处理它们。

152

protected void processHierarchyBoundsEvent(HierarchyEvent e)

通过将发生在此组件上的层次结构边界事件分派给任何已注册的HierarchyBoundsListener 对象。

153

protected void processHierarchyEvent(HierarchyEvent e)

通过将层次结构事件分派给任何已注册的 HierarchyListener 对象来处理此组件上发生的层次结构事件。

154

protectedvoid processInputMethodEvent(InputMethodEvent e)

通过将输入法事件分派给任何已注册的 InputMethodListener 对象来处理此组件上发生的输入法事件。

155

protected void processKeyEvent(KeyEvent e)

通过将键事件分派给任何已注册的 KeyListener 来处理此组件上发生的键事件对象。

156

protected void processMouseEvent(MouseEvent e)

通过将鼠标事件分派给任何已注册的 MouseListener 对象来处理此组件上发生的鼠标事件。

157

protected void processMouseMotionEvent(MouseEvent e)

通过将鼠标事件分派给任何已注册的 MouseMotionListener 对象来处理此组件上发生的鼠标移动事件。

158

protected void processMouseWheelEvent(MouseWheelEvent e)

通过将鼠标滚轮事件分派给任何已注册的 MouseWheelListener 来处理此组件上发生的鼠标滚轮事件对象。

159

void remove(MenuComponent popup)

从组件中移除指定的弹出菜单。

160

void removeComponentListener(ComponentListener l)

移除指定的组件侦听器,使其不再从此组件接收组件事件。

161

void removeFocusListener(FocusListener l)

移除指定的焦点侦听器,使其不再从此组件接收焦点事件。

162

void removeHierarchyBoundsListener(HierarchyBoundsListener l)

移除指定的层次结构边界侦听器,使其不再接收来自此组件的层次结构边界事件。

163

void removeHierarchyListener(HierarchyListener l)

移除指定的层次结构侦听器,使其不再接收来自此组件的层次结构更改事件。

164

void removeInputMethodListener(InputMethodListener l)

移除指定的输入法侦听器,使其不再接收来自此组件的输入法事件。

165

void removeKeyListener(KeyListener l)

移除指定的按键监听器,使其不再接收来自此组件的按键事件。

166

void removeMouseListener(MouseListener l)

移除指定的鼠标监听器,使其不再接收来自此组件的鼠标事件。

167

void removeMouseMotionListener(MouseMotionListener l)

移除指定的鼠标动作监听器,使其不再接收来自此组件的鼠标动作事件。

168

void removeMouseWheelListener(MouseWheelListener l)

移除指定的鼠标滚轮监听器,使其不再接收此组件的鼠标滚轮事件。

169

void removeNotify()

通过销毁其本机屏幕资源使此组件无法显示。

170

void removePropertyChangeListener(PropertyChangeListener listener)

从侦听器列表中删除 PropertyChangeListener。

171

void remove Property ChangeListener(String propertyName, PropertyChange Listener listener)

从特定属性的侦听器列表中删除 PropertyChangeListener。

172

void repaint()

重新绘制此组件。

173

void repaint(int x,int y,int width,int height)

重新绘制此组件的指定矩形。

174

void repaint(long tm)

重新绘制组件。

175

void repaint(long tm,int x,int y,int width,int height)

在 tm 内重新绘制此组件的指定矩形毫秒。

176

void requestFocus()

请求此组件获得输入焦点,并且此组件的顶级祖先成为焦点窗口。

177

protected boolean requestFocus(boolean temporary)

请求此组件获得输入焦点,并且此组件的顶级祖先成为焦点窗口。

178

boolean requestFocusInWindow()

如果此组件的顶级祖先已经是焦点,则请求此组件获得输入焦点窗口。

179

protected boolean requestFocusInWindow(boolean temporary)

如果此组件的顶级祖先已经是焦点窗口,则请求此组件获取输入焦点。

180

void reshape(int x,int y,int width,int height)

已弃用。从 JDK 1.1 版开始,由 setBounds(int, int, int, int) 取代。

181

void resize(Dimension d)

已弃用。从 JDK 1.1 版开始,由 setSize(Dimension) 取代。

182

void resize(int width,int height)

已弃用。从 JDK 1.1 版开始,由 setSize(int, int) 取代。

183

void setBackground(Color c)

设置此组件的背景颜色。

184

void setBounds(int x,int y,int width,int height)

移动并调整此组件的大小。

185

void setBounds(Rectangle r)

移动并调整此组件的大小以符合新的边界矩形r.

186

void setComponentOrientation(ComponentOrientation o)

设置用于排序此组件内的元素或文本的语言敏感方向。

187

void setCursor(Cursor cursor)

将光标图像设置为指定光标。

188

void setDropTarget(DropTarget dt)

将 DropTarget 与此组件关联。

189

void setEnabled(boolean b)

启用或禁用此组件,具体取决于参数 b 的值。

190

void setFocusable(boolean focusable)

将此组件的可聚焦状态设置为指定值。

191

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

为此组件设置给定遍历操作的焦点遍历键。

192

void setFocusTraversalKeysEnabled(boolean focusTraversalKeysEnabled)

设置是否为此组件启用焦点遍历键。

193

void setFont(Font f)

设置此组件的字体。

194

void setForeground(Color c)

设置此组件的前景色。

195

void setIgnoreRepaint(boolean ignoreRepaint)

设置是否应忽略从操作系统收到的绘制消息。

196

void setLocale(Locale l)

设置此组件的区域设置。

197

void setLocation(int x,int y)

将此组件移动到新位置。

198

void setLocation(Point p)

将此组件移动到新位置。

199

void setMaximumSize(Dimension maximumSize)

将此组件的最大大小设置为常量值。

200

void setMinimumSize(Dimension minimumSize)

将此组件的最小大小设置为常量值。

201

void setName(String name)

将组件的名称设置为指定的字符串。

202

void setPreferredSize(Dimension preferredSize)

将此组件的首选大小设置为常量值。

203

void setSize(Dimension d)

调整此组件的大小,使其宽度为 d.width,高度为 d.height。

204void setSize(int width,int height)

调整此组件的大小,使其宽度为 width,高度为 height。

205

void setVisible(boolean b)

根据参数值显示或隐藏此组件b.

206

void show()

已弃用。从 JDK 1.1 版开始,由 setVisible(boolean) 取代。

207

void show(boolean b)

已弃用。从 JDK 1.1 版开始,由 setVisible(boolean) 取代。

208

Dimension size()

已弃用。从 JDK 1.1 版开始,由 getSize() 取代。

209

String toString()

返回此组件及其值的字符串表示形式。

210

void transferFocus()

将焦点转移到下一个组件,就好像此组件是焦点所有者一样。

211

void transferFocusBackward()

将焦点转移到前一个组件,就好像此组件是焦点所有者一样。

212

void transferFocusUpCycle()

将焦点向上转移一个焦点遍历循环。

213

void update(Graphics g)

更新此组件。

214

void verify()

确保此组件具有有效布局。

215

Rectangle bounds()

已弃用。从 JDK 1.1 版开始,由 getBounds() 取代。

216

protected AWTEvent coalesceEvents(AWTEvent establishedEvent, AWTEvent newEvent)

可能将正在发布的事件与现有事件合并。

217

protected String paramString()

返回表示此组件状态的字符串。

218

protected void firePropertyChange(String propertyName,int oldValue,int newValue)

支持报告整数的绑定属性更改属性。

219

Dimension preferredSize()

已弃用。从 JDK 版本 1.1 开始,由 getPreferredSize() 取代。

220

boolean prepareImage(Image image, ImageObserver observer)

准备一个图像以在此组件上进行渲染。

221

Dimension minimumSize()

已弃用。从 JDK 版本 1.1 开始,由 getMinimumSize() 取代。

继承的方法

此类从以下类继承方法:

  • java.lang.Object

awt_controls.html