所有类


java.awt
类 Component

java.lang.Object
  继承者 java.awt.Component
所有已实现的接口:
ImageObserver, MenuContainer, Serializable
直接已知子类:
Button, Canvas, Checkbox, Choice, Container, Label, List, Scrollbar, TextComponent

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

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 及其引用的所有内容也都被序列化。问题是,原本没打算序列化的侦听器也被同时序列化了。为分别判断 MyAppActionListener 是否可序列化,可使用一个嵌套类,如下面示例所示:
    import java.awt.*;
    import java.awt.event.*;
    import java.io.Serializable;

    class MyApp java.io.Serializable
    {
         BigObjectThatShouldNotBeSerializedWithAButton bigOne;
         Button aButton = new Button();

         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  classComponent.AccessibleAWTComponent
          用来为可访问性提供默认支持的 Component 的内部类。
protected  classComponent.BltBufferStrategy
          用于将屏幕外的画面以位图传输方式传输到一个组件的内部类。
protected  classComponent.FlipBufferStrategy
          在组件上翻转缓冲区的内部类。
 
字段摘要
static floatBOTTOM_ALIGNMENT
          getAlignmentY 的易于使用的常量。
static floatCENTER_ALIGNMENT
          getAlignmentYgetAlignmentX 的易于使用的常量。
static floatLEFT_ALIGNMENT
          getAlignmentX 的易于使用的常量。
static floatRIGHT_ALIGNMENT
          getAlignmentX 的易于使用的常量。
static floatTOP_ALIGNMENT
          getAlignmentY() 的易于使用的常量。
 
从接口 java.awt.image.ImageObserver 继承的字段
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
构造方法摘要
protected Component()
          构造一个新组件。
 
方法摘要
 booleanaction(Event evt, Object what)
          已过时。 从 JDK version 1.1 开始,应该将此组件作为组件(激发操作事件)上的 ActionListener 来注册。
 voidadd(PopupMenu popup)
          向组件添加指定的弹出菜单。
 voidaddComponentListener(ComponentListener l)
          添加指定的组件侦听器,接收此组件发出的组件事件。
 voidaddFocusListener(FocusListener l)
          添加指定的焦点侦听器,当此组件获得输入焦点时能够接收此组件发出的焦点事件。
 voidaddHierarchyBoundsListener(HierarchyBoundsListener l)
          添加指定的层次结构边界侦听器,当此容器所属的层次结构发生变化时能够接收此组件发出的层次结构边界事件。
 voidaddHierarchyListener(HierarchyListener l)
          添加指定的层次结构侦听器,当此容器所属的层次结构发生变化时能够接收此组件发出的层次结构变化事件。
 voidaddInputMethodListener(InputMethodListener l)
          添加指定的输入方法侦听器,接收此组件发出的输入方法事件。
 voidaddKeyListener(KeyListener l)
          添加指定的按键侦听器,接收此组件发出的按键事件。
 voidaddMouseListener(MouseListener l)
          添加指定的鼠标侦听器,接收此组件发出的鼠标事件。
 voidaddMouseMotionListener(MouseMotionListener l)
          添加指定的鼠标移动侦听器,接收此组件发出的鼠标移动事件。
 voidaddMouseWheelListener(MouseWheelListener l)
          添加指定的鼠标轮侦听器,接收此组件发出的鼠标轮事件。
 voidaddNotify()
          通过将此 Component 连接到一个本机屏幕资源使其成为可显示的。
 voidaddPropertyChangeListener(PropertyChangeListener listener)
          向侦听器列表添加一个 PropertyChangeListener。
 voidaddPropertyChangeListener(String propertyName, PropertyChangeListener listener)
          向指定属性的侦听器列表添加一个 PropertyChangeListener。
 voidapplyComponentOrientation(ComponentOrientation orientation)
          设置此组件及其包含的所有组件的 ComponentOrientation 属性。
 booleanareFocusTraversalKeysSet(int id)
          返回是否为此 Component 显式定义了给定焦点遍历操作的焦点遍历键 Set。
 Rectanglebounds()
          已过时。 从 JDK version 1.1 开始,由 getBounds() 取代。
 intcheckImage(Image image, ImageObserver observer)
          返回指定图像屏幕表示的构造状态。
 intcheckImage(Image image, int width, int height, ImageObserver observer)
          返回指定图像屏幕表示的构造状态。
protected  AWTEventcoalesceEvents(AWTEvent existingEvent, AWTEvent newEvent)
          将加入的事件与已有的事件组合在一起。
 booleancontains(int x, int y)
          检查组件是否“包含”指定的点,其中 xy 是相对于此组件的坐标系统定义的。
 booleancontains(Point p)
          检查组件是否“包含”指定的点,其中该点的 xy 坐标是相对于此组件的坐标系统定义的。
 ImagecreateImage(ImageProducer producer)
          由指定的图像生成器创建一幅图像。
 ImagecreateImage(int width, int height)
          创建一幅用于双缓冲的、可在屏幕外绘制的图像。
 VolatileImagecreateVolatileImage(int width, int height)
          创建一幅用于双缓冲的、可变的、可在屏幕外绘制的图像。
 VolatileImagecreateVolatileImage(int width, int height, ImageCapabilities caps)
          创建一幅具有给定容量的、可变的、可在屏幕外绘制的图像。
 voiddeliverEvent(Event e)
          已过时。 从 JDK version 1.1 开始,由 dispatchEvent(AWTEvent e) 取代。
 voiddisable()
          已过时。 从 JDK version 1.1 开始,由 setEnabled(boolean) 取代。
protected  voiddisableEvents(long eventsToDisable)
          禁用由传递给此组件的指定事件屏蔽参数所定义的事件。
 voiddispatchEvent(AWTEvent e)
          为组件或其子组件之一指派事件。
 voiddoLayout()
          提示布局管理器布局此组件。
 voidenable()
          已过时。 从 JDK version 1.1 开始,由 setEnabled(boolean) 取代。
 voidenable(boolean b)
          已过时。 从 JDK version 1.1 开始,由 setEnabled(boolean) 取代。
protected  voidenableEvents(long eventsToEnable)
          启用由传递给此组件的指定事件屏蔽参数所定义的事件。
 voidenableInputMethods(boolean enable)
          启用或禁用此方法的输入方法支持。
protected  voidfirePropertyChange(String propertyName, boolean oldValue, boolean newValue)
          支持报告布尔属性的 bound 属性改变。
 voidfirePropertyChange(String propertyName, byte oldValue, byte newValue)
          报告 bound 属性的改变。
 voidfirePropertyChange(String propertyName, char oldValue, char newValue)
          报告 bound 属性的改变。
 voidfirePropertyChange(String propertyName, double oldValue, double newValue)
          报告 bound 属性的改变。
 voidfirePropertyChange(String propertyName, float oldValue, float newValue)
          报告 bound 属性的改变。
protected  voidfirePropertyChange(String propertyName, int oldValue, int newValue)
          支持报告整数属性的 bound 属性改变。
 voidfirePropertyChange(String propertyName, long oldValue, long newValue)
          报告 bound 属性的改变。
protected  voidfirePropertyChange(String propertyName, Object oldValue, Object newValue)
          支持报告 Object 属性的 bound 属性改变。
 voidfirePropertyChange(String propertyName, short oldValue, short newValue)
          报告 bound 属性的改变。
 AccessibleContextgetAccessibleContext()
          获得与此 Component 相关的 AccessibleContext
 floatgetAlignmentX()
          返回 x 轴的对齐方式。
 floatgetAlignmentY()
          返回 y 轴的对齐方式。
 ColorgetBackground()
          获得组件的背景色。
 RectanglegetBounds()
          以 Rectangle 对象的形式获得组件的边界。
 RectanglegetBounds(Rectangle rv)
          将组件的边界存储到“返回值”rv 中并返回 rv
 ColorModelgetColorModel()
          获得用于在输出设备上显示组件的 ColorModel 实例。
 ComponentgetComponentAt(int x, int y)
          确定此组件或其直接子组件之一是否包含(xy)位置,并且如果是,则返回包含该位置的组件。
 ComponentgetComponentAt(Point p)
          返回包含指定点的组件或子组件。
 ComponentListener[]getComponentListeners()
          返回在此组件上所有已注册的组件侦听器的数组。
 ComponentOrientationgetComponentOrientation()
          检索用于排序此组件内的元素或文本的语言敏感的方向。
 CursorgetCursor()
          获得组件中的光标集合。
 DropTargetgetDropTarget()
          获得与此 Component 相关的 DropTarget
 ContainergetFocusCycleRootAncestor()
          返回作为此 Component 焦点遍历循环的焦点循环根的 Container。
 FocusListener[]getFocusListeners()
          返回在此组件上所有已注册的焦点侦听器的数组。
 Set<AWTKeyStroke>getFocusTraversalKeys(int id)
          返回此 Component 的给定遍历操作的焦点遍历键 Set。
 booleangetFocusTraversalKeysEnabled()
          返回是否已为此 Component 启用了焦点遍历键。
 FontgetFont()
          获得组件的字体。
 FontMetricsgetFontMetrics(Font font)
          获得指定字体的字体规格。
 ColorgetForeground()
          获得组件的前景色。
 GraphicsgetGraphics()
          为组件创建一个图形上下文。
 GraphicsConfigurationgetGraphicsConfiguration()
          获得与此 Component 相关的 GraphicsConfiguration
 intgetHeight()
          返回组件的当前高度。
 HierarchyBoundsListener[]getHierarchyBoundsListeners()
          返回在此组件上所有已注册的层次结构边界侦听器的数组。
 HierarchyListener[]getHierarchyListeners()
          返回在此组件上所有已注册的层次结构侦听器的数组。
 booleangetIgnoreRepaint()
           
 InputContextgetInputContext()
          获得此组件使用的输入上下文,用于处理在此组件中输入文本时与输入方法的通信。
 InputMethodListener[]getInputMethodListeners()
          返回在此组件上所有已注册的输入方法侦听器的数组。
 InputMethodRequestsgetInputMethodRequests()
          获得输入方法请求处理程序,该处理程序支持此组件输入方法发出的请求。
 KeyListener[]getKeyListeners()
          返回在此组件上所有已注册的按键侦听器的数组。
<T extends EventListener>
T[]
getListeners(Class<T> listenerType)
          返回一个当前在此 Component 上作为 FooListener 注册的所有对象的数组。
 LocalegetLocale()
          获得组件的语言环境。
 PointgetLocation()
          获得组件的位置,形式是指定组件左上角的一个点。
 PointgetLocation(Point rv)
          将组件的 x,y 原点存储到“返回值” rv 中并返回 rv
 PointgetLocationOnScreen()
          获得组件的位置,形式是一个指定屏幕坐标空间中组件左上角的一个点。
 DimensiongetMaximumSize()
          获得组件的最大尺寸。
 DimensiongetMinimumSize()
          获得组件的最小尺寸。
 MouseListener[]getMouseListeners()
          返回在此组件上所有已注册的鼠标侦听器的数组。
 MouseMotionListener[]getMouseMotionListeners()
          返回在此组件上所有已注册的鼠标移动侦听器的数组。
 PointgetMousePosition()
          如果此 Component 正好位于鼠标指针下,则返回鼠标指针在 Component 的坐标空间中的位置;否则返回 null
 MouseWheelListener[]getMouseWheelListeners()
          返回在此组件上所有已注册的鼠标轮侦听器的数组。
 StringgetName()
          获得组件的名称。
 ContainergetParent()
          获得此组件的父级。
 java.awt.peer.ComponentPeergetPeer()
          已过时。 从 JDK version 1.1 开始,程序不应直接操作同位体;由 boolean isDisplayable() 取代。
 DimensiongetPreferredSize()
          获得组件的首选大小。
 PropertyChangeListener[]getPropertyChangeListeners()
          返回在此组件上所有已注册的属性更改侦听器的数组。
 PropertyChangeListener[]getPropertyChangeListeners(String propertyName)
          返回与指定属性相关联的所有侦听器的数组。
 DimensiongetSize()
          以 Dimension 对象的形式返回组件的大小。
 DimensiongetSize(Dimension rv)
          将组件的宽度/高度存储到“返回值”rv 中并返回 rv
 ToolkitgetToolkit()
          获得此组件的工具包。
 ObjectgetTreeLock()
          获得此组件用于 AWT 组件树和布局操作的锁定对象(拥有线程同步监视器的对象)。
 intgetWidth()
          返回组件的当前宽度。
 intgetX()
          返回组件原点的当前 x 坐标。
 intgetY()
          返回组件原点的当前 y 坐标。
 booleangotFocus(Event evt, Object what)
          已过时。 从 JDK version 1.1 开始,由 processFocusEvent(FocusEvent) 取代。
 booleanhandleEvent(Event evt)
          已过时。 从 JDK version 1.1 开始,由 processEvent(AWTEvent) 取代。
 booleanhasFocus()
          如果此 Component 是焦点所有者,则返回 true
 voidhide()
          已过时。 从 JDK version 1.1 开始,由 setVisible(boolean) 取代。
 booleanimageUpdate(Image img, int infoflags, int x, int y, int w, int h)
          图像已改变时重绘组件。
 booleaninside(int x, int y)
          已过时。 从 JDK version 1.1 开始,由 contains(int, int) 取代。
 voidinvalidate()
          使此组件无效。
 booleanisBackgroundSet()
          返回是否已为此组件显示地设置了背景色。
 booleanisCursorSet()
          返回是否已为此组件显示地设置了光标。
 booleanisDisplayable()
          确定此组件是否可以显示。
 booleanisDoubleBuffered()
          如果将此组件绘制到一个随后复制到屏幕上的屏幕外图像(“缓冲区”),则返回 true。
 booleanisEnabled()
          确定此组件是否已启用。
 booleanisFocusable()
          返回此 Component 是否可以获得焦点。
 booleanisFocusCycleRoot(Container container)
          返回指定的 Container 是否为此 Component 焦点遍历循环的焦点循环根。
 booleanisFocusOwner()
          如果此 Component 是焦点所有者,则返回 true
 booleanisFocusTraversable()
          已过时。 在 1.4 中,由 isFocusable() 取代。
 booleanisFontSet()
          返回是否已为此组件显示地设置了字体。
 booleanisForegroundSet()
          返回是否已为此组件显式地设置了前景色。
 booleanisLightweight()
          轻量组件没有本机工具包同位体。
 booleanisMaximumSizeSet()
          如果已将最大尺寸设置为非 null 值,则返回 true,否则返回 false。
 booleanisMinimumSizeSet()
          返回是否已用非 null 值调用了 setMinimumSize
 booleanisOpaque()
          如果组件是完全不透明的,则返回 true,默认返回 false。
 booleanisPreferredSizeSet()
          如果已将首选大小设置为非 null 值,则返回 true,否则返回 false。
 booleanisShowing()
          确定此组件是否在屏幕上显示。
 booleanisValid()
          确定组件是否有效。
 booleanisVisible()
          确定此组件在其父容器可见时是否应该可见。
 booleankeyDown(Event evt, int key)
          已过时。 从 JDK version 1.1 开始,由 processKeyEvent(KeyEvent) 取代。
 booleankeyUp(Event evt, int key)
          已过时。 从 JDK version 1.1 开始,由 processKeyEvent(KeyEvent) 取代。
 voidlayout()
          已过时。 从 JDK version 1.1 开始,由 doLayout() 取代。
 voidlist()
          将组件列表打印到标准系统输出流 System.out
 voidlist(PrintStream out)
          将组件列表打印到指定的输出流。
 voidlist(PrintStream out, int indent)
          将列表从指定的缩进开始打印到指定的输出流。
 voidlist(PrintWriter out)
          将列表打印到指定的 PrintWriter。
 voidlist(PrintWriter out, int indent)
          将列表从指定的缩进开始打印到指定的 PrintWriter。
 Componentlocate(int x, int y)
          已过时。 从 JDK version 1.1 开始,由 getComponentAt(int, int) 取代。
 Pointlocation()
          已过时。 从 JDK version 1.1 开始,由 getLocation() 取代。
 booleanlostFocus(Event evt, Object what)
          已过时。 从 JDK version 1.1 开始,由 processFocusEvent(FocusEvent) 取代。
 DimensionminimumSize()
          已过时。 从 JDK version 1.1 开始,由 getMinimumSize() 取代。
 booleanmouseDown(Event evt, int x, int y)
          已过时。 从 JDK version 1.1 开始,由 processMouseEvent(MouseEvent) 取代。
 booleanmouseDrag(Event evt, int x, int y)
          已过时。 从 JDK version 1.1 开始,由 processMouseMotionEvent(MouseEvent) 取代。
 booleanmouseEnter(Event evt, int x, int y)
          已过时。 从 JDK version 1.1 开始,由 processMouseEvent(MouseEvent) 取代。
 booleanmouseExit(Event evt, int x, int y)
          已过时。 从 JDK version 1.1 开始,由 processMouseEvent(MouseEvent) 取代。
 booleanmouseMove(Event evt, int x, int y)
          已过时。 从 JDK version 1.1 开始,由 processMouseMotionEvent(MouseEvent) 取代。
 booleanmouseUp(Event evt, int x, int y)
          已过时。 从 JDK version 1.1 开始,由 processMouseEvent(MouseEvent) 取代。
 voidmove(int x, int y)
          已过时。 从 JDK version 1.1 开始,由 setLocation(int, int) 取代。
 voidnextFocus()
          已过时。 从 JDK version 1.1 开始,由 transferFocus() 取代。
 voidpaint(Graphics g)
          绘制此组件。
 voidpaintAll(Graphics g)
          绘制此组件及其所有子组件。
protected  StringparamString()
          返回此组件状态的字符串表示形式。
 booleanpostEvent(Event e)
          已过时。 从 JDK version 1.1 开始,由 dispatchEvent(AWTEvent) 取代。
 DimensionpreferredSize()
          已过时。 从 JDK version 1.1 开始,由 getPreferredSize() 取代。
 booleanprepareImage(Image image, ImageObserver observer)
          准备一幅在此组件上呈现的图像。
 booleanprepareImage(Image image, int width, int height, ImageObserver observer)
          以指定的宽度和高度准备一幅在在此组件上呈现的图像。
 voidprint(Graphics g)
          打印此组件。
 voidprintAll(Graphics g)
          打印此组件及其所有子组件。
protected  voidprocessComponentEvent(ComponentEvent e)
          处理组件上发生的组件事件,方法是将其指派到任意已注册的 ComponentListener 对象。
protected  voidprocessEvent(AWTEvent e)
          处理在组件上发生的事件。
protected  voidprocessFocusEvent(FocusEvent e)
          处理组件上发生的焦点事件,方法是将其指派到任意已注册的 FocusListener 对象。
protected  voidprocessHierarchyBoundsEvent(HierarchyEvent e)
          处理组件上发生的层次结构边界事件,方法是将其指派到任意已注册的 HierarchyBoundsListener 对象。
protected  voidprocessHierarchyEvent(HierarchyEvent e)
          处理组件上发生的层次结构事件,方法是将其指派到任意已注册的 HierarchyListener 对象。
protected  voidprocessInputMethodEvent(InputMethodEvent e)
          处理组件上发生的输入方法事件,方法是将其指派到任意已注册的 InputMethodListener 对象。
protected  voidprocessKeyEvent(KeyEvent e)
          处理组件上发生的按键事件,方法是将其指派到任意已注册的 KeyListener 对象。
protected  voidprocessMouseEvent(MouseEvent e)
          处理组件上发生的鼠标事件,方法是将其指派到任意已注册的 MouseListener 对象。
protected  voidprocessMouseMotionEvent(MouseEvent e)
          处理组件上发生的鼠标移动事件,方法是将其指派到任意已注册的 MouseMotionListener 事件。
protected  voidprocessMouseWheelEvent(MouseWheelEvent e)
          处理组件上发生的鼠标轮事件,方法是将其指派到任意已注册的 MouseWheelListener 对象。
 voidremove(MenuComponent popup)
          从组件移除指定的弹出菜单。
 voidremoveComponentListener(ComponentListener l)
          移除指定的组件侦听器,不再接收此组件发出的组件事件。
 voidremoveFocusListener(FocusListener l)
          移除指定的焦点侦听器,不再接收此组件发出的焦点事件。
 voidremoveHierarchyBoundsListener(HierarchyBoundsListener l)
          移除指定的层次结构边界侦听器,不再接收此组件发出的层次结构边界事件如果参数所指定的侦听器尚未添加到此组件,则此方法不起作用,也不抛出异常。
 voidremoveHierarchyListener(HierarchyListener l)
          移除指定的层次结构侦听器,不再接收此组件发出的层次结构变化事件。
 voidremoveInputMethodListener(InputMethodListener l)
          移除指定的输入方法侦听器,不再接收此组件发出的输入方法事件。
 voidremoveKeyListener(KeyListener l)
          移除指定的按键侦听器,不再接收此组件发出的按键事件。
 voidremoveMouseListener(MouseListener l)
          移除指定的鼠标侦听器,不再接收此组件发出的鼠标事件。
 voidremoveMouseMotionListener(MouseMotionListener l)
          移除指定的鼠标移动侦听器,不再接收此组件发出的鼠标移动事件。
 voidremoveMouseWheelListener(MouseWheelListener l)
          移除指定的鼠标轮侦听器,不再接收此组件发出的鼠标轮事件。
 voidremoveNotify()
          通过销毁此 Component 的本机屏幕资源使其成为不可显示的。
 voidremovePropertyChangeListener(PropertyChangeListener listener)
          从侦听器列表移除一个 PropertyChangeListener。
 voidremovePropertyChangeListener(String propertyName, PropertyChangeListener listener)
          从指定属性的侦听器列表中移除一个 PropertyChangeListener
 voidrepaint()
          重绘此组件。
 voidrepaint(int x, int y, int width, int height)
          重绘组件的指定矩形区域。
 voidrepaint(long tm)
          重绘组件。
 voidrepaint(long tm, int x, int y, int width, int height)
          在 tm 毫秒内重绘组件的指定矩形区域。
 voidrequestFocus()
          请求此 Component 获得输入焦点,并且此 Component 的顶层祖先成为获得焦点的 Window。
protected  booleanrequestFocus(boolean temporary)
          请求此 Component 获得输入焦点,并且此 Component 的顶层祖先成为获得焦点的 Window
 booleanrequestFocusInWindow()
          如果此 Component 的顶层祖先已经是获得焦点的窗口,则请求此 Component 获得输入焦点。
protected  booleanrequestFocusInWindow(boolean temporary)
          如果此 Component 的顶层祖先已经是获得焦点的 Window,则请求此 Component 获得输入焦点。
 voidreshape(int x, int y, int width, int height)
          已过时。 从 JDK version 1.1 开始,由 setBounds(int, int, int, int) 取代。
 voidresize(Dimension d)
          已过时。 从 JDK version 1.1 开始,由 setSize(Dimension) 取代。
 voidresize(int width, int height)
          已过时。 从 JDK version 1.1 开始,由 setSize(int, int) 取代。
 voidsetBackground(Color c)
          设置组件的背景色。
 voidsetBounds(int x, int y, int width, int height)
          移动组件并调整其大小。
 voidsetBounds(Rectangle r)
          移动组件并调整其大小,使其符合新的有界矩形 r
 voidsetComponentOrientation(ComponentOrientation o)
          设置语言敏感的方向,用于排序此组件内的元素或文本。
 voidsetCursor(Cursor cursor)
          为指定的光标设置光标图像。
 voidsetDropTarget(DropTarget dt)
          将组件与 DropTarget 相关联。
 voidsetEnabled(boolean b)
          根据参数 b 的值启用或禁用此组件。
 voidsetFocusable(boolean focusable)
          将此 Component 的焦点状态设置为指定值。
 voidsetFocusTraversalKeys(int id, Set<? extends AWTKeyStroke> keystrokes)
          为此 Component 的给定遍历操作设置焦点遍历键。
 voidsetFocusTraversalKeysEnabled(boolean focusTraversalKeysEnabled)
          设置是否为此 Component 启用焦点遍历键。
 voidsetFont(Font f)
          设置组件的字体。
 voidsetForeground(Color c)
          设置组件的前景色。
 voidsetIgnoreRepaint(boolean ignoreRepaint)
          设置是否应该忽略从操作系统接受的绘制消息。
 voidsetLocale(Locale l)
          设置组件的语言环境。
 voidsetLocation(int x, int y)
          将组件移到新位置。
 voidsetLocation(Point p)
          将组件移到新位置。
 voidsetMaximumSize(Dimension maximumSize)
          将组件的最大尺寸设置为常量值。
 voidsetMinimumSize(Dimension minimumSize)
          将组件的最小尺寸设置为常量值。
 voidsetName(String name)
          将组件的名称设置为指定的字符串。
 voidsetPreferredSize(Dimension preferredSize)
          将组件的首选大小设置为常量值。
 voidsetSize(Dimension d)
          调整组件的大小,使其宽度为 d.width,高度为 d.height
 voidsetSize(int width, int height)
          调整组件的大小,使其宽度为 width,高度为 height
 voidsetVisible(boolean b)
          根据参数 b 的值显示或隐藏此组件。
 voidshow()
          已过时。 从 JDK version 1.1 开始,由 setVisible(boolean) 取代。
 voidshow(boolean b)
          已过时。 从 JDK version 1.1 开始,由 setVisible(boolean) 取代。
 Dimensionsize()
          已过时。 从 JDK version 1.1 开始,由 getSize() 取代。
 StringtoString()
          返回此组件及其值的字符串表示形式。
 voidtransferFocus()
          将焦点转移到下一个组件,就好像此 Component 曾是焦点所有者。
 voidtransferFocusBackward()
          将焦点转移到前一个组件,就好像此 Component 曾是焦点所有者。
 voidtransferFocusUpCycle()
          将焦点向上转移一个焦点遍历循环。
 voidupdate(Graphics g)
          更新组件。
 voidvalidate()
          确保组件具有有效的布局。
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

字段详细信息

TOP_ALIGNMENT

public static final float TOP_ALIGNMENT
getAlignmentY() 的易于使用的常量。指定组件顶部对齐方式。

另请参见:
getAlignmentY(), 常量字段值

CENTER_ALIGNMENT

public static final float CENTER_ALIGNMENT
getAlignmentYgetAlignmentX 的易于使用的常量。指定组件居中对齐的方式。

另请参见:
getAlignmentX(), getAlignmentY(), 常量字段值

BOTTOM_ALIGNMENT

public static final float BOTTOM_ALIGNMENT
getAlignmentY 的易于使用的常量。指定组件底部对齐的方式。

另请参见:
getAlignmentY(), 常量字段值

LEFT_ALIGNMENT

public static final float LEFT_ALIGNMENT
getAlignmentX 的易于使用的常量。指定组件左对齐的方式。

另请参见:
getAlignmentX(), 常量字段值

RIGHT_ALIGNMENT

public static final float RIGHT_ALIGNMENT
getAlignmentX 的易于使用的常量。指定组件右对齐的方式。

另请参见:
getAlignmentX(), 常量字段值
构造方法详细信息

Component

protected Component()
构造一个新组件。可以直接扩展 Component 类,以便创建不利用本机不透明窗口的轻量组件。轻量组件必须由组件树中较高处的本机容器所承载(例如由 Frame 对象承载)。

方法详细信息

getName

public String getName()
获得组件的名称。

返回:
组件的名称
从以下版本开始:
JDK1.1
另请参见:
setName(java.lang.String)

setName

public void setName(String name)
将组件的名称设置为指定的字符串。

参数:
name - 要成为组件名称的字符串。
从以下版本开始:
JDK1.1
另请参见:
getName()

getParent

public Container getParent()
获得此组件的父级。

返回:
此组件的父级容器
从以下版本开始:
JDK1.0