|
JavaTM 2 Platform Standard Ed. 6 |
|||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
java.lang.Objectjava.awt.Component
public abstract class Component
component 是一个具有图形表示能力的对象,可在屏幕上显示,并可与用户进行交互。典型图形用户界面中的按钮、复选框和滚动条都是组件示例。
Component 类是与菜单不相关的 Abstract Window Toolkit 组件的抽象超类。还可以直接扩展类 Component 来创建一个轻量级组件。轻量级组件是与本机不透明窗口不相关的组件。
Serializable 协议的 AWT 侦听器,注意这一点很重要。如果具有侦听器的 AWT 对象未标记为可序列化,则在 writeObject 时将会被丢弃。开发人员始终需要考虑序列化对象的意义。需要注意的一种情形是:
import java.awt.*;
import java.awt.event.*;
import java.io.Serializable;
class MyApp implements ActionListener, Serializable
{
BigObjectThatShouldNotBeSerializedWithAButton bigOne;
Button aButton = new Button();
MyApp()
{
// Oops, now aButton has a listener with a reference
// to bigOne!
aButton.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
System.out.println("Hello There");
}
}
在此示例中,通过 aButton 自身进行序列化会使得 MyApp 及其引用的所有内容也都被序列化。问题是,原本没打算序列化的侦听器也被同时序列化了。为分别判断 MyApp 和 ActionListener 是否可序列化,可使用一个嵌套类,如下面示例所示:
import java.awt.*;
import java.awt.event.*;
import java.io.Serializable;
class MyApp java.io.Serializable
{
BigObjectThatShouldNotBeSerializedWithAButton bigOne;
Button aButton = new Button();
static class MyActionListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
System.out.println("Hello There");
}
}
MyApp()
{
aButton.addActionListener(new MyActionListener());
}
}
注:有关 AWT 和 Swing 所用绘制机制的更多信息,包括如何编写最高效的绘制代码的信息,请参阅 Painting in AWT and Swing。
有关焦点子系统的详情,请参阅 The Java Tutorial 中的 How to Use the Focus Subsystem 部分,以及 Focus Specification 了解更多信息。
| 嵌套类摘要 | |
|---|---|
protected class |
Component.AccessibleAWTComponent
用来为可访问性提供默认支持的 Component 的内部类。 |
static class |
Component.BaselineResizeBehavior
常见方式的枚举,指示组件的基线可以随大小的更改而更改。 |
protected class |
Component.BltBufferStrategy
用于将屏幕外的画面以位图传输方式传输到一个组件的内部类。 |
protected class |
Component.FlipBufferStrategy
在组件上翻转缓冲区的内部类。 |
| 字段摘要 | |
|---|---|
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() 的易于使用的常量。 |
| 从接口 java.awt.image.ImageObserver 继承的字段 |
|---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
| 构造方法摘要 | |
|---|---|
protected |
Component()
构造一个新组件。 |
| 方法摘要 | ||
|---|---|---|
boolean |
action(Event evt,
Object what)
已过时。 从 JDK version 1.1 开始,应该将此组件作为组件(激发动作事件)上的 ActionListener 来注册。 |
|
void |
add(PopupMenu popup)
向组件添加指定的弹出菜单。 |
|
void |
addComponentListener(ComponentListener l)
添加指定的组件侦听器,以接收发自此组件的组件事件。 |
|
void |
addFocusListener(FocusListener l)
添加指定的焦点侦听器,以便当此组件获得输入焦点时能够接收发自此组件的焦点事件。 |
|
void |
addHierarchyBoundsListener(HierarchyBoundsListener l)
添加指定的层次结构边界侦听器,以便当此容器所属的层次结构发生变化时接收发自此组件的层次结构边界事件。 |
|
void |
addHierarchyListener(HierarchyListener l)
添加指定的层次结构侦听器,以便当此容器所属的层次结构发生变化时接收发自此组件的层次结构变化事件。 |
|
void |
addInputMethodListener(InputMethodListener l)
添加指定的输入方法侦听器,以接收发自此组件的输入方法事件。 |
|
void |
addKeyListener(KeyListener l)
添加指定的按键侦听器,以接收发自此组件的按键事件。 |
|
void |
addMouseListener(MouseListener l)
添加指定的鼠标侦听器,以接收发自此组件的鼠标事件。 |
|
void |
addMouseMotionListener(MouseMotionListener l)
添加指定的鼠标移动侦听器,以接收发自此组件的鼠标移动事件。 |
|
void |
addMouseWheelListener(MouseWheelListener l)
添加指定的鼠标滚轮侦听器,以接收发自此组件的鼠标滚轮事件。 |
|
void |
addNotify()
通过将此 Component 连接到一个本机屏幕资源使其成为可显示的。 |
|
void |
addPropertyChangeListener(PropertyChangeListener listener)
向侦听器列表添加一个 PropertyChangeListener。 |
|
void |
addPropertyChangeListener(String propertyName,
PropertyChangeListener listener)
向指定属性的侦听器列表添加一个 PropertyChangeListener。 |
|
void |
applyComponentOrientation(ComponentOrientation orientation)
设置此组件及其包含的所有组件的 ComponentOrientation 属性。 |
|
boolean |
areFocusTraversalKeysSet(int id)
返回是否为此 Component 显式定义了给定焦点遍历操作的焦点遍历键 Set。 |
|
Rectangle |
bounds()
已过时。 从 JDK version 1.1 开始,由 getBounds() 取代。 |
|
int |
checkImage(Image image,
ImageObserver observer)
返回指定图像屏幕表示的构造状态。 |
|
int |
checkImage(Image image,
int width,
int height,
ImageObserver observer)
返回指定图像屏幕表示的构造状态。 |
|
protected AWTEvent |
coalesceEvents(AWTEvent existingEvent,
AWTEvent newEvent)
将正发送的事件与现有事件组合在一起。 |
|
boolean |
contains(int x,
int y)
检查组件是否“包含”指定的点,其中 x 和 y 是相对于此组件的坐标系定义的。 |
|
boolean |
contains(Point p)
检查组件是否“包含”指定的点,其中该点的 x 和 y 坐标是相对于此组件的坐标系定义的。 |
|
Image |
createImage(ImageProducer producer)
根据指定的图像生成器创建一幅图像。 |
|
Image |
createImage(int width,
int height)
创建一幅用于双缓冲的、可在屏幕外绘制的图像。 |
|
VolatileImage |
createVolatileImage(int width,
int height)
创建一幅用于双缓冲的、可变的、可在屏幕外绘制的图像。 |
|
VolatileImage |
createVolatileImage(int width,
int height,
ImageCapabilities caps)
创建一幅具有给定能力的、可变的、可在屏幕外绘制的图像。 |
|
void |
deliverEvent(Event e)
已过时。 从 JDK version 1.1 开始,由 dispatchEvent(AWTEvent e) 取代。 |
|
void |
disable()
已过时。 从 JDK version 1.1 开始,由 setEnabled(boolean) 取代。 |
|
protected void |
disableEvents(long eventsToDisable)
禁用由传递给此组件的指定事件掩码参数所定义的事件。 |
|
void |
dispatchEvent(AWTEvent e)
为组件或其子组件之一指派事件。 |
|
void |
doLayout()
提示布局管理器布局此组件。 |
|
void |
enable()
已过时。 从 JDK version 1.1 开始,由 setEnabled(boolean) 取代。 |
|
void |
enable(boolean b)
已过时。 从 JDK version 1.1 开始,由 setEnabled(boolean) 取代。 |
|
protected void |
enableEvents(long eventsToEnable)
启用由传递给此组件的指定事件掩码参数所定义的事件。 |
|
void |
enableInputMethods(boolean enable)
启用或禁用此组件的输入方法支持。 |
|
protected void |
firePropertyChange(String propertyName,
boolean oldValue,
boolean newValue)
支持报告布尔属性的绑定属性改变。 |
|
void |
firePropertyChange(String propertyName,
byte oldValue,
byte newValue)
报告绑定属性的改变。 |
|
void |
firePropertyChange(String propertyName,
char oldValue,
char newValue)
报告绑定属性的改变。 |
|
void |
firePropertyChange(String propertyName,
double oldValue,
double newValue)
报告绑定属性的改变。 |
|
void |
firePropertyChange(String propertyName,
float oldValue,
float newValue)
报告绑定属性的改变。 |
|
protected void |
firePropertyChange(String propertyName,
int oldValue,
int newValue)
支持报告整数属性的绑定属性改变。 |
|
void |
firePropertyChange(String propertyName,
long oldValue,
long newValue)
报告绑定属性的改变。 |
|
protected void |
firePropertyChange(String propertyName,
Object oldValue,
Object newValue)
支持报告 Object 属性的绑定属性改变。 |
|
void |
firePropertyChange(String propertyName,
short oldValue,
short newValue)
报告绑定属性的改变。 |
|
AccessibleContext |
getAccessibleContext()
获取与此 Component 相关的 AccessibleContext。 |
|
float |
getAlignmentX()
返回 x 轴的对齐方式。 |
|
float |
getAlignmentY()
返回 y 轴的对齐方式。 |
|
Color |
getBackground()
获取组件的背景色。 |
|
int |
getBaseline(int width,
int height)
返回基线。 |
|
Component.BaselineResizeBehavior |
getBaselineResizeBehavior()
返回一个指示组件的基线如何随大小发生更改的枚举。 |
|
Rectangle |
getBounds()
以 Rectangle 对象的形式获取组件的边界。 |
|
Rectangle |
getBounds(Rectangle rv)
将组件的边界存储到“返回值”rv 中并返回 rv。 |
|
ColorModel |
getColorModel()
获取用于在输出设备上显示组件的 ColorModel 实例。 |
|
Component |
getComponentAt(int x,
int y)
确定此组件或其直接子组件之一是否包含(x,y)位置,并且如果是,则返回包含该位置的组件。 |
|
Component |
getComponentAt(Point p)
返回包含指定点的组件或子组件。 |
|
ComponentListener[] |
getComponentListeners()
返回在此组件上所有已注册的组件侦听器的数组。 |
|
ComponentOrientation |
getComponentOrientation()
检索将用于排序此组件内的元素或文本的语言敏感的方向。 |
|
Cursor |
getCursor()
获取组件中的光标集合。 |
|
DropTarget |
getDropTarget()
获取与此 Component 相关的 DropTarget。 |
|
Container |
getFocusCycleRootAncestor()
返回作为此 Component 焦点遍历循环的焦点循环根的 Container。 |
|
FocusListener[] |
getFocusListeners()
返回在此组件上所有已注册的焦点侦听器的数组。 |
|
Set<AWTKeyStroke> |
getFocusTraversalKeys(int id)
返回此 Component 的给定遍历操作的焦点遍历键 Set。 |
|
boolean |
getFocusTraversalKeysEnabled()
返回是否已为此 Component 启用了焦点遍历键。 |
|
Font |
getFont()
获取组件的字体。 |
|
FontMetrics |
getFontMetrics(Font font)
获取指定字体的字体规格。 |
|
Color |
getForeground()
获取组件的前景色。 |
|
Graphics |
getGraphics()
为组件创建一个图形上下文。 |
|
GraphicsConfiguration |
getGraphicsConfiguration()
获取与此 Component 相关的 GraphicsConfiguration。 |
|
int |
getHeight()
返回组件的当前高度。 |
|
HierarchyBoundsListener[] |
getHierarchyBoundsListeners()
返回在此组件上所有已注册的层次结构边界侦听器的数组。 |
|
HierarchyListener[] |
getHierarchyListeners()
返回在此组件上所有已注册的层次结构侦听器的数组。 |
|
boolean |
getIgnoreRepaint()
|
|
InputContext |
getInputContext()
获取此组件使用的输入上下文,用于处理在此组件中输入文本时与输入方法的通信。 |
|
InputMethodListener[] |
getInputMethodListeners()
返回在此组件上所有已注册的输入方法侦听器的数组。 |
|
InputMethodRequests |
getInputMethodRequests()
获取输入方法请求处理程序,该处理程序支持此组件输入方法发出的请求。 |
|
KeyListener[] |
getKeyListeners()
返回在此组件上所有已注册的按键侦听器的数组。 |
|
|
getListeners(Class<T> listenerType)
返回一个当前在此 Component 上作为 FooListener 注册的所有对象的数组。 |
|
Locale |
getLocale()
获取组件的语言环境。 |
|
Point |
getLocation()
获取组件的位置,形式是指定组件左上角的一个点。 |
|
Point |
getLocation(Point rv)
将组件的 x,y 原点存储到“返回值” rv 中并返回 rv。 |
|
Point |
getLocationOnScreen()
获取组件的位置,形式是一个指定屏幕坐标空间中组件左上角的一个点。 |
|
Dimension |
getMaximumSize()
获取组件的最大大小。 |
|
Dimension |
getMinimumSize()
获取组件的最小大小。 |
|
MouseListener[] |
getMouseListeners()
返回在此组件上所有已注册的鼠标侦听器的数组。 |
|
MouseMotionListener[] |
getMouseMotionListeners()
返回在此组件上所有已注册的鼠标移动侦听器的数组。 |
|
Point |
getMousePosition()
如果此 Component 正好位于鼠标指针下,则返回鼠标指针在该 Component 的坐标空间中的位置;否则返回 null。 |
|
MouseWheelListener[] |
getMouseWheelListeners()
返回在此组件上所有已注册的鼠标滚轮侦听器的数组。 |
|
String |
getName()
获取组件的名称。 |
|
Container |
getParent()
获取此组件的父级。 |
|
java.awt.peer.ComponentPeer |
getPeer()
已过时。 从 JDK version 1.1 开始,程序不应直接操作同位体;由 boolean isDisplayable() 取代。 |
|
Dimension |
getPreferredSize()
获取组件的首选大小。 |
|
PropertyChangeListener[] |
getPropertyChangeListeners()
返回在此组件上所有已注册的属性更改侦听器的数组。 |
|
PropertyChangeListener[] |
getPropertyChangeListeners(String propertyName)
返回与指定属性相关联的所有侦听器的数组。 |
|
Dimension |
getSize()
以 Dimension 对象的形式返回组件的大小。 |
|
Dimension |
getSize(Dimension rv)
将组件的宽度/高度存储到“返回值”rv 中并返回 rv。 |
|
Toolkit |
getToolkit()
获取此组件的工具包。 |
|
Object |
getTreeLock()
获取此组件用于 AWT 组件树和布局操作的锁定对象(拥有线程同步监视器的对象)。 |
|
int |
getWidth()
返回组件的当前宽度。 |
|
int |
getX()
返回组件原点的当前 x 坐标。 |
|
int |
getY()
返回组件原点的当前 y 坐标。 |
|
boolean |
gotFocus(Event evt,
Object what)
已过时。 从 JDK version 1.1 开始,由 processFocusEvent(FocusEvent) 取代。 |
|
boolean |
handleEvent(Event evt)
已过时。 从 JDK version 1.1 开始,由 processEvent(AWTEvent) 取代。 |
|
boolean |
hasFocus()
如果此 Component 是焦点所有者,则返回 true。 |
|
void |
hide()
已过时。 从 JDK version 1.1 开始,由 setVisible(boolean) 取代。 |
|
boolean |
imageUpdate(Image img,
int infoflags,
int x,
int y,
int w,
int h)
图像已改变时重绘组件。 |
|
boolean |
inside(int x,
int y)
已过时。 从 JDK version 1.1 开始,由 contains(int, int) 取代。 |
|
void |
invalidate()
使此组件无效。 |
|
boolean |
isBackgroundSet()
返回是否已为此组件显示地设置了背景色。 |
|
boolean |
isCursorSet()
返回是否已为此组件显示地设置了光标。 |
|
boolean |
isDisplayable()
确定此组件是否可以显示。 |
|
boolean |
isDoubleBuffered()
如果将此组件绘制到一个随后复制到屏幕上的屏幕外图像(“缓冲区”),则返回 true。 |
|
boolean |
isEnabled()
确定此组件是否已启用。 |
|
boolean |
isFocusable()
返回此 Component 是否可以获得焦点。 |
|
boolean |
isFocusCycleRoot(Container container)
返回指定的 Container 是否为此 Component 焦点遍历循环的焦点循环根。 |
|
boolean |
isFocusOwner()
如果此 Component 是焦点所有者,则返回 true。 |
|
boolean |
isFocusTraversable()
已过时。 从 1.4 开始,由 isFocusable() 取代。 |
|
boolean |
isFontSet()
返回是否已为此组件显示地设置了字体。 |
|
boolean |
isForegroundSet()
返回是否已为此组件显式地设置了前景色。 |
|
boolean |
isLightweight()
轻量级组件没有本机工具包同位体。 |
|
boolean |
isMaximumSizeSet()
如果已将最大大小设置为非 null 值,则返回 true,否则返回 false。 |
|
boolean |
isMinimumSizeSet()
返回是否已用非 null 值调用了 setMinimumSize。 |
|
boolean |
isOpaque()
如果组件是完全不透明的,则返回 true,默认返回 false。 |
|
boolean |
isPreferredSizeSet()
如果已将首选大小设置为非 null 值,则返回 true,否则返回 false。 |
|
boolean |
isShowing()
确定此组件是否在屏幕上显示。 |
|
boolean |
isValid()
确定组件是否有效。 |
|
boolean |
isVisible()
确定此组件在其父容器可见时是否应该可见。 |
|
boolean |
keyDown(Event evt,
int key)
已过时。 从 JDK version 1.1 开始,由 processKeyEvent(KeyEvent) 取代。 |
|
boolean |
keyUp(Event evt,
int key)
已过时。 从 JDK version 1.1 开始,由 processKeyEvent(KeyEvent) 取代。 |
|
void |
layout()
已过时。 从 JDK version 1.1 开始,由 doLayout() 取代。 |
|
void |
list()
将组件列表打印到标准系统输出流 System.out。 |
|
void |
list(PrintStream out)
将组件列表打印到指定的输出流。 |
|
void |
list(PrintStream out,
int indent)
将列表从指定的缩排开始打印到指定的打印流。 |
|
void |
list(PrintWriter out)
将列表打印到指定的打印编写器。 |
|
void |
list(PrintWriter out,
int indent)
将列表从指定的缩排开始打印到指定的打印编写器。 |
|
Component |
locate(int x,
int y)
已过时。 从 JDK version 1.1 开始,由 getComponentAt(int, int) 取代。 |
|
Point |
location()
已过时。 从 JDK version 1.1 开始,由 getLocation() 取代。 |
|
boolean |
lostFocus(Event evt,
Object what)
已过时。 从 JDK version 1.1 开始,由 processFocusEvent(FocusEvent) 取代。 |
|
Dimension |
minimumSize()
已过时。 从 JDK version 1.1 开始,由 getMinimumSize() 取代。 |
|
boolean |
mouseDown(Event evt,
int x,
int y)
已过时。 从 JDK version 1.1 开始,由 processMouseEvent(MouseEvent) 取代。 |
|
boolean |
mouseDrag(Event evt,
int x,
int y)
已过时。 从 JDK version 1.1 开始,由 processMouseMotionEvent(MouseEvent) 取代。 |
|
boolean |
mouseEnter(Event evt,
int x,
int y)
已过时。 从 JDK version 1.1 开始,由 processMouseEvent(MouseEvent) 取代。 |
|
boolean |
mouseExit(Event evt,
int x,
int y)
已过时。 从 JDK version 1.1 开始,由 processMouseEvent(MouseEvent) 取代。 |
|
boolean |
mouseMove(Event evt,
int x,
int y)
已过时。 从 JDK version 1.1 开始,由 processMouseMotionEvent(MouseEvent) 取代。 |
|
boolean |
mouseUp(Event evt,
int x,
int y)
已过时。 从 JDK version 1.1 开始,由 processMouseEvent(MouseEvent) 取代。 |
|
void |
move(int x,
int y)
已过时。 从 JDK version 1.1 开始,由 setLocation(int, int) 取代。 |
|
void |
nextFocus()
已过时。 从 JDK version 1.1 开始,由 transferFocus() 取代。 |
|
void |
paint(Graphics g)
绘制此组件。 |
|
void |
paintAll(Graphics g)
绘制此组件及其所有子组件。 |
|
protected String |
paramString()
返回此组件状态的字符串表示形式。 |
|
boolean |
postEvent(Event e)
已过时。 从 JDK version 1.1 开始,由 dispatchEvent(AWTEvent) 取代。 |
|
Dimension |
preferredSize()
已过时。 从 JDK version 1.1 开始,由 getPreferredSize() 取代。 |
|
boolean |
prepareImage(Image image,
ImageObserver observer)
准备一幅在此组件上呈现的图像。 |
|
boolean |
prepareImage(Image image,
int width,
int height,
ImageObserver observer)
以指定的宽度和高度准备一幅在此组件上呈现的图像。 |
|
void |
print(Graphics g)
打印此组件。 |
|
void |
printAll(Graphics g)
打印此组件及其所有子组件。 |
|
protected void |
processComponentEvent(ComponentEvent e)
处理组件上发生的组件事件,方法是将其指派到任意已注册的 ComponentListener 对象。 |
|
protected void |
processEvent(AWTEvent e)
处理组件上发生的事件。 |
|
protected void |
processFocusEvent(FocusEvent e)
处理组件上发生的焦点事件,方法是将其指派到任意已注册的 FocusListener 对象。 |
|
protected void |
processHierarchyBoundsEvent(HierarchyEvent e)
处理组件上发生的层次结构边界事件,方法是将其指派到任意已注册的 HierarchyBoundsListener 对象。 |
|
protected void |
processHierarchyEvent(HierarchyEvent e)
处理组件上发生的层次结构事件,方法是将其指派到任意已注册的 HierarchyListener 对象。 |
|
protected void |
processInputMethodEvent(InputMethodEvent e)
处理组件上发生的输入方法事件,方法是将其指派到任意已注册的 InputMethodListener 对象。 |
|
protected void |
processKeyEvent(KeyEvent e)
处理组件上发生的按键事件,方法是将其指派到任意已注册的 KeyListener 对象。 |
|
protected void |
processMouseEvent(MouseEvent e)
处理组件上发生的鼠标事件,方法是将其指派到任意已注册的 MouseListener 对象。 |
|
protected void |
processMouseMotionEvent(MouseEvent e)
处理组件上发生的鼠标移动事件,方法是将其指派到任意已注册的 MouseMotionListener 事件。 |
|
protected void |
processMouseWheelEvent(MouseWheelEvent e)
处理组件上发生的鼠标滚轮事件,方法是将其指派到任意已注册的 MouseWheelListener 对象。 |
|
void |
remove(MenuComponent popup)
从组件移除指定的弹出菜单。 |
|
void |
removeComponentListener(ComponentListener l)
移除指定的组件侦听器,以便它不再接收发自此组件的组件事件。 |
|
void |
removeFocusListener(FocusListener l)
移除指定的焦点侦听器,以便它不再接收发自此组件的焦点事件。 |
|
void |
removeHierarchyBoundsListener(HierarchyBoundsListener l)
移除指定的层次结构边界侦听器,以便它不再接收发自此组件的层次结构边界事件。 |
|
void |
removeHierarchyListener(HierarchyListener l)
移除指定的层次结构侦听器,以便它不再接收发自此组件的层次结构变化事件。 |
|
void |
removeInputMethodListener(InputMethodListener l)
移除指定的输入方法侦听器,以便它不再接收发自此组件的输入方法事件。 |
|
void |
removeKeyListener(KeyListener l)
移除指定的按键侦听器,以便它不再接收发自此组件的按键事件。 |
|
void |
removeMouseListener(MouseListener l)
移除指定的鼠标侦听器,以便它不再接收发自此组件的鼠标事件。 |
|
void |
removeMouseMotionListener(MouseMotionListener l)
移除指定的鼠标移动侦听器,以便它不再接收发自此组件的鼠标移动事件。 |
|
void |
removeMouseWheelListener(MouseWheelListener l)
移除指定的鼠标滚轮侦听器,以便它不再接收发自此组件的鼠标滚轮事件。 |
|
void |
removeNotify()
通过销毁此 Component 的本机屏幕资源使其成为不可显示的。 |
|
void |
removePropertyChangeListener(PropertyChangeListener listener)
从侦听器列表移除一个 PropertyChangeListener。 |
|
void |
removePropertyChangeListener(String propertyName,
PropertyChangeListener listener)
从指定属性的侦听器列表中移除一个 PropertyChangeListener。 |
|
void |
repaint()
重绘此组件。 |
|
void |
repaint(int x,
int y,
int width,
int height)
重绘组件的指定矩形区域。 |
|
void |
repaint(long tm)
重绘组件。 |
|
void |
repaint(long tm,
int x,
int y,
int width,
int height)
在 tm 毫秒内重绘组件的指定矩形区域。 |
|
void |
requestFocus()
请求此 Component 获取输入焦点,并且此 Component 的顶层祖先成为获得焦点的 Window。 |
|
protected boolean |
requestFocus(boolean temporary)
请求此 Component 获取输入焦点,并且此 Component 的顶层祖先成为获得焦点的 Window。 |
|
boolean |
requestFocusInWindow()
如果此 Component 的顶层祖先已经是获得焦点的 Window,则请求此 Component 获取输入焦点。 |
|
protected boolean |
requestFocusInWindow(boolean temporary)
如果此 Component 的顶层祖先已经是获得焦点的 Window,则请求此 Component 获取输入焦点。 |
|
void |
reshape(int x,
int y,
int width,
int height)
已过时。 从 JDK version 1.1 开始,由 setBounds(int, int, int, int) 取代。 |
|
void |
resize(Dimension d)
已过时。 从 JDK version 1.1 开始,由 setSize(Dimension) 取代。 |
|
void |
resize(int width,
int height)
已过时。 从 JDK version 1.1 开始,由 setSize(int, int) 取代。 |
|
void |
setBackground(Color c)
设置组件的背景色。 |
|
void |
setBounds(int x,
int y,
int width,
int height)
移动组件并调整其大小。 |
|
void |
setBounds(Rectangle r)
移动组件并调整其大小,使其符合新的有界矩形 r。 |
|
void |
setComponentOrientation(ComponentOrientation o)
设置语言敏感的方向,用于排序此组件内的元素或文本。 |
|
void |
setCursor(Cursor cursor)
为指定的光标设置光标图像。 |
|
void |
setDropTarget(DropTarget dt)
将组件与 DropTarget 相关联。 |
|
void |
setEnabled(boolean b)
根据参数 b 的值启用或禁用此组件。 |
|
void |
setFocusable(boolean focusable)
将此 Component 的焦点状态设置为指定值。 |
|
void |
setFocusTraversalKeys(int id,
Set<? extends AWTKeyStroke> keystrokes)
为此 Component 的给定遍历操作设置焦点遍历键。 |
|
void |
setFocusTraversalKeysEnabled(boolean focusTraversalKeysEnabled)
设置是否为此 Component 启用焦点遍历键。 |
|
void |
setFont(Font f)
设置组件的字体。 |
|
void |
setForeground(Color c)
设置组件的前景色。 |
|
void |
setIgnoreRepaint(boolean ignoreRepaint)
设置是否应该忽略从操作系统接受的绘制消息。 |
|
void |
setLocale(Locale l)
设置组件的语言环境。 |
|
void |
setLocation(int x,
int y)
将组件移到新位置。 |
|
void |
setLocation(Point p)
将组件移到新位置。 |
|
void |
setMaximumSize(Dimension maximumSize)
将组件的最大大小设置为常量值。 |
|
void |
setMinimumSize(Dimension minimumSize)
将组件的最小大小设置为常量值。 |
|
void |
setName(String name)
将组件的名称设置为指定的字符串。 |
|
void |
setPreferredSize(Dimension preferredSize)
将组件的首选大小设置为常量值。 |
|
void |
setSize(Dimension d)
调整组件的大小,使其宽度为 d.width,高度为 d.height。 |
|
void |
setSize(int width,
int height)
调整组件的大小,使其宽度为 width,高度为 height。 |
|
void |
setVisible(boolean b)
根据参数 b 的值显示或隐藏此组件。 |
|
void |
show()
已过时。 从 JDK version 1.1 开始,由 setVisible(boolean) 取代。 |
|
void |
show(boolean b)
已过时。 从 JDK version 1.1 开始,由 setVisible(boolean) 取代。 |
|
Dimension |
size()
已过时。 从 JDK version 1.1 开始,由 getSize() 取代。 |
|
String |
toString()
返回此组件及其值的字符串表示形式。 |
|
void |
transferFocus()
将焦点转移到下一个组件,就好像此 Component 曾是焦点所有者。 |
|
void |
transferFocusBackward()
将焦点转移到前一个组件,就好像此 Component 曾是焦点所有者。 |
|
void |
transferFocusUpCycle()
将焦点向上转移一个焦点遍历循环。 |
|
void |
update(Graphics g)
更新组件。 |
|
void |
validate()
确保组件具有有效的布局。 |
|
| 从类 java.lang.Object 继承的方法 |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| 字段详细信息 |
|---|
public static final float TOP_ALIGNMENT
getAlignmentY() 的易于使用的常量。指定组件顶部对齐方式。
getAlignmentY(),
常量字段值public static final float CENTER_ALIGNMENT
getAlignmentY 和 getAlignmentX 的易于使用的常量。指定组件居中对齐方式。
getAlignmentX(),
getAlignmentY(),
常量字段值public static final float BOTTOM_ALIGNMENT
getAlignmentY 的易于使用的常量。指定组件底部对齐方式。
getAlignmentY(),
常量字段值public static final float LEFT_ALIGNMENT
getAlignmentX 的易于使用的常量。指定组件左对齐方式。
getAlignmentX(),
常量字段值public static final float RIGHT_ALIGNMENT
getAlignmentX 的易于使用的常量。指定组件右对齐方式。
getAlignmentX(),
常量字段值| 构造方法详细信息 |
|---|
protected Component()
Component 类,以便创建不利用本机不透明窗口的轻量级组件。轻量级组件必须由组件树中较高处的本机容器所承载(例如由 Frame 对象承载)。
| 方法详细信息 |
|---|
public String getName()
setName(java.lang.String)public void setName(String name)
name - 要成为组件名称的字符串。getName()public Container getParent()
@Deprecated public java.awt.peer.ComponentPeer getPeer()
boolean isDisplayable() 取代。
public void setDropTarget(DropTarget dt)
DropTarget 相关联。仅在已启用 Component 时才接收放置。
dt - DropTargetisEnabled()public DropTarget getDropTarget()
Component 相关的 DropTarget。
public GraphicsConfiguration getGraphicsConfiguration()
Component 相关的 GraphicsConfiguration。如果尚未给 Component 分配指定的 GraphicsConfiguration,则返回该 Component 对象顶层容器的 GraphicsConfiguration。如果已经创建了 Component 但尚未添加到 Container 中,则此方法返回 null。
Component 使用的 GraphicsConfiguration,或者返回 nullpublic final Object getTreeLock()
public Toolkit getToolkit()
public boolean isValid()
true;否则返回 falsevalidate(),
invalidate()public boolean isDisplayable()
将组件添加到一个可显示的包含层次结构时,或者其包含层次结构变成可显示时,该组件才成为可显示的组件。当包含层次结构的祖先窗口被打包或变为可见时,它才成为可显示的。
从可显示的包含层次结构中移除某个组件,或者该组件的包含层次结构变成不可显示时,该组件就成为不可显示的组件。当包含层次结构的祖先窗口被移除时,它才变成不可显示的。
true;否则返回 falseContainer.add(Component),
Window.pack(),
Window.show(),
Container.remove(Component),
Window.dispose()public boolean isVisible()
Frame 对象等顶层组件除外。
true;否则返回 falsesetVisible(boolean)
public Point getMousePosition()
throws HeadlessException
Component 正好位于鼠标指针下,则返回鼠标指针在该 Component 的坐标空间中的位置;否则返回 null。如果屏幕上未显示 Component,那么即使鼠标指针位于将显示 Component 的区域之上,此方法也只是返回 null。如果 Component 被其他 Component 或本机窗口所部分或完全遮掩,则仅在鼠标指针位于 Component 未被遮掩的部分之上时,此方法才返回非 null 值。
对于 Container,如果鼠标位于 Container 本身之上或位于其后代之上时,则此方法返回非 null 值。如果需要将子容器排除在外,请使用 Container.getMousePosition(boolean)。
有时鼠标的准确坐标并不重要,唯一重要的是指定的 Component 是否位于鼠标指针下。如果此方法的返回值为 null,则鼠标指针不位于 Component 的上边。
Component 的坐标,或者返回 null。