目录

Component

介绍 (Introduction)

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

类声明

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

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

字段 (Field)

以下是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()的易用常量。

类构造函数

SN 构造函数和描述
1

protected Component()

这将创建一个新的组件。

类方法

SN 方法和描述
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)

返回是否已为此Component显式定义了给定焦点遍历操作的焦点遍历键Set。

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 producer)

从指定的图像生成器创建图像。

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 version 1.1开始,由dispatchEvent(AWTEvent e)取代。

26

void disable()

已过时。 从JDK version 1.1开始,由setEnabled(boolean)取代。

27

protected void disableEvents(long eventsToDisable)

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

28

void dispatchEvent(AWTEvent e)

将事件调度到此组件或其子组件之一。

29

void doLayout()

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

30

void enable()

已过时。 从JDK version 1.1开始,由setEnabled(boolean)取代。

31

void enable(boolean b)

已过时。 从JDK version 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)

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

41

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

报告绑定的属性更改。

42

AccessibleContext getAccessibleContext()

获取与此Component关联的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)

将此组件的边界存储为return value 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()

获取与此Component关联的DropTarget。

57

Container getFocusCycleRootAncestor()

返回Container,它是此Component焦点遍历循环的焦点循环根。

58

FocusListener[] getFocusListeners()

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

59

Set《AWTKeyStroke》 getFocusTraversalKeys(int id)

返回此Component的给定遍历操作的焦点遍历键Set。

60

boolean getFocusTraversalKeysEnabled()

返回是否为此Component启用了焦点遍历键。

61

Font getFont()

获取此组件的字体。

62

FontMetrics getFontMetrics(Font font)

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

63

Color getForeground()

获取此组件的前景色。

64

Graphics getGraphics()

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

65

GraphicsConfiguration getGraphicsConfiguration()

获取与此Component关联的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 EventListener》 T[] getListeners(Class《T》 listenerType)

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

75

Locale getLocale()

获取此组件的语言环境。

76

Point getLocation()

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

77

Point getLocation(Point rv)

将此组件的x,y原点存储为return value rv并返回rv。

78

Point getLocationOnScreen()

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

79

Dimension getMaximumSize()

获取此组件的最大大小。

80

Dimension getMinimumSize()

获取此组件的最小大小。

81

MouseListener[] getMouseListeners()

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

82

MouseMotionListener[] getMouseMotionListeners()

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

83

Point getMousePosition()

如果Component直接位于鼠标指针下,则返回此Component的坐标空间中鼠标指针的位置,否则返回null。

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

String getName()

获取组件的名称。

86

Container getParent()

获取此组件的父级。

87

java.awt.peer.ComponentPeer getPeer() Deprecated. As of JDK version 1.1, programs should not directly manipulate peers; replaced by boolean isDisplayable().

88

Dimension getPreferredSize()

获取此组件的首选大小。

89

PropertyChangeListener[] getPropertyChangeListeners()

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

90

Property ChangeListener[] getProperty ChangeListeners (String propertyName)

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

91

Dimension getSize()

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

92

Dimension getSize(Dimension rv)Stores the width/height of this component into return value rv and return 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()

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

101

void hide()

已过时。 从JDK version 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 version 1.1开始,由contains(int,int)取代。

104

void invalidate()

使此组件无效。

105

boolean isBackgroundSet()

返回是否已为此Component显式设置背景颜色。

106

boolean isCursorSet()

返回是否已为此Component显式设置游标。

107

boolean isDisplayable()

确定此组件是否可显示。

108

boolean isDoubleBuffered()

如果将此组件绘制到屏幕外图像( buffer ),则返回true

之后会复制到屏幕上。

109

boolean isEnabled()

确定是否启用此组件。

110

boolean isFocusable()

返回是否可以聚焦此Component。

111

boolean isFocusCycleRoot(Container container)

返回指定的Container是否是此Component的焦点遍历循环的焦点循环根。

112

boolean isFocusOwner()

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

113

boolean isFocusTraversable()

已过时。 从1.4开始,由isFocusable()取代。

114

boolean isFontSet()

返回是否已为此Component显式设置字体。

115

boolean isForegroundSet()

返回是否已为此Component显式设置前景色。

116

boolean isLightweight()

轻量级组件没有本机工具包同级。

117

boolean isMaximumSizeSet()

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

118

boolean isMinimumSizeSet()

返回是否已使用非null值调用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 version 1.1开始,由processKeyEvent(KeyEvent)取代。

125

boolean keyUp(Event evt,int key)

已过时。 从JDK version 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

Component locate(int x,int y)

已过时。 从JDK version 1.1开始,由getComponentAt(int,int)取代。

133

Point location()

已过时。 从JDK version 1.1开始,由getLocation()取代。

134

boolean lostFocus(Event evt, Object what)

已过时。 从JDK version 1.1开始,由processFocusEvent(FocusEvent)取代。

135

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

已过时。 从JDK version 1.1开始,由processMouseEvent(MouseEvent)取代。

136

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

已过时。 从JDK version 1.1开始,由processMouseMotionEvent(MouseEvent)取代。

137

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

已过时。 从JDK version 1.1开始,由processMouseEvent(MouseEvent)取代。

138

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

已过时。 从JDK version 1.1开始,由processMouseEvent(MouseEvent)取代..

139

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

已过时。 从JDK version 1.1开始,由processMouseMotionEvent(MouseEvent)取代..

140

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

已过时。 从JDK version 1.1开始,由processMouseEvent(MouseEvent)取代。

141

void move(int x,int y)

已过时。 从JDK version 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 version 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)

处理在此组件上发生的事件。

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()

请求此Component获取输入焦点,并且此Component的顶级祖先成为焦点Window。

177

protected boolean requestFocus(boolean temporary)

请求此Component获取输入焦点,并且此Component的顶级祖先成为焦点Window。

178

boolean requestFocusInWindow()

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

179

protected boolean requestFocusInWindow(boolean temporary)

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

180

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

已过时。 从JDK version 1.1开始,由setBounds(int,int,int,int)取代。

181

void resize(Dimension d)

已过时。 从JDK version 1.1开始,由setSize(Dimension)取代。

182

void resize(int width,int height)

已过时。 从JDK version 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)

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

191

void setFocusTraversalKeys(int id, Set《? extends AWTKeyStroke》 keystrokes)

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

192

void setFocusTraversalKeysEnabled(boolean focusTraversalKeysEnabled)

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

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。

204 void setSize(int width,int height)

调整此组件的大小,使其具有宽度宽度和高度。

205

void setVisible(boolean b)

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

206

void show()

已过时。 从JDK version 1.1开始,由setVisible(boolean)取代。

207

void show(boolean b)

已过时。 从JDK version 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 validate()

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

215

Rectangle bounds()

已过时。 从JDK 1.1版开始,由getBounds()取代。

216

protected AWTEvent coalesceEvents(AWTEvent existingEvent, AWTEvent newEvent)

可能合并使用现有事件发布的事件。

217

protected String paramString()

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

218

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

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

219

Dimension preferredSize()

已过时。 从JDK version 1.1开始,由getPreferredSize()取代。

220

boolean prepareImage(Image image, ImageObserver observer)

准备要在此组件上呈现的图像。

221

Dimension minimumSize()

已过时。 从JDK 1.1版开始,由getMinimumSize()取代。

方法继承

该类继承以下类中的方法:

  • java.lang.Object

↑回到顶部↑
WIKI教程 @2018