component.java

来自「Mac OS X 10.4.9 for x86 Source Code gcc」· Java 代码 · 共 2,357 行 · 第 1/5 页

JAVA
2,357
字号
   * @return this component's foreground color, or null   * @see #setForeground(Color)   */  public Color getForeground()  {    if (foreground != null)      return foreground;    return parent == null ? SystemColor.windowText : parent.getForeground();  }  /**   * Sets this component's foreground color to the specified color. This is a   * bound property.   *   * @param c the new foreground color   * @see #getForeground()   */  public void setForeground(Color c)  {    firePropertyChange("foreground", foreground, c);    if (peer != null)      peer.setForeground(c);    foreground = c;  }  /**   * Tests if the foreground was explicitly set, or just inherited from the   * parent.   *   * @return true if the foreground has been set   * @since 1.4   */  public boolean isForegroundSet()  {    return foreground != null;  }  /**   * Returns this component's background color. If not set, this is inherited   * from the parent.   *   * @return the background color of the component, or null   * @see #setBackground(Color)   */  public Color getBackground()  {    if (background != null)      return background;    return parent == null ? SystemColor.window : parent.getBackground();  }  /**   * Sets this component's background color to the specified color. The parts   * of the component affected by the background color may by system dependent.   * This is a bound property.   *   * @param c the new background color   * @see #getBackground()   */  public void setBackground(Color c)  {    // If c is null, inherit from closest ancestor whose bg is set.    if (c == null && parent != null)      c = parent.getBackground();    firePropertyChange("background", background, c);    if (peer != null && c != null)      peer.setBackground(c);    background = c;  }  /**   * Tests if the background was explicitly set, or just inherited from the   * parent.   *   * @return true if the background has been set   * @since 1.4   */  public boolean isBackgroundSet()  {    return background != null;  }  /**   * Returns the font in use for this component. If not set, this is inherited   * from the parent.   *   * @return the font for this component   * @see #setFont(Font)   */  public Font getFont()  {    if (font != null)      return font;    if (parent != null)      return parent.getFont ();    else      return new Font ("Dialog", Font.PLAIN, 12);  }  /**   * Sets the font for this component to the specified font. This is a bound   * property.   *   * @param newFont the new font for this component   *    * @see #getFont()   */  public void setFont(Font newFont)  {    if (font == newFont)      return;        Font oldFont = font;    font = newFont;    if (peer != null)      peer.setFont(font);    firePropertyChange("font", oldFont, newFont);    invalidate();  }  /**   * Tests if the font was explicitly set, or just inherited from the parent.   *   * @return true if the font has been set   * @since 1.4   */  public boolean isFontSet()  {    return font != null;  }  /**   * Returns the locale for this component. If this component does not   * have a locale, the locale of the parent component is returned.   *   * @return the locale for this component   * @throws IllegalComponentStateException if it has no locale or parent   * @see #setLocale(Locale)   * @since 1.1   */  public Locale getLocale()  {    if (locale != null)      return locale;    if (parent == null)      throw new IllegalComponentStateException        ("Component has no parent: can't determine Locale");    return parent.getLocale();  }  /**   * Sets the locale for this component to the specified locale. This is a   * bound property.   *   * @param newLocale the new locale for this component   */  public void setLocale(Locale newLocale)  {    if (locale == newLocale)      return;    Locale oldLocale = locale;    locale = newLocale;    firePropertyChange("locale", oldLocale, newLocale);    // New writing/layout direction or more/less room for localized labels.    invalidate();  }  /**   * Returns the color model of the device this componet is displayed on.   *   * @return this object's color model   * @see Toolkit#getColorModel()   */  public ColorModel getColorModel()  {    GraphicsConfiguration config = getGraphicsConfiguration();    return config != null ? config.getColorModel()      : getToolkit().getColorModel();  }  /**   * Returns the location of this component's top left corner relative to   * its parent component. This may be outdated, so for synchronous behavior,   * you should use a component listner.   *   * @return the location of this component   * @see #setLocation(int, int)   * @see #getLocationOnScreen()   * @since 1.1   */  public Point getLocation()  {    return location ();  }  /**   * Returns the location of this component's top left corner in screen   * coordinates.   *   * @return the location of this component in screen coordinates   * @throws IllegalComponentStateException if the component is not showing   */  public Point getLocationOnScreen()  {    if (! isShowing())      throw new IllegalComponentStateException("component not showing");    // We know peer != null here.    return peer.getLocationOnScreen();  }  /**   * Returns the location of this component's top left corner relative to   * its parent component.   *   * @return the location of this component   * @deprecated use {@link #getLocation()} instead   */  public Point location()  {    return new Point (x, y);  }  /**   * Moves this component to the specified location, relative to the parent's   * coordinates. The coordinates are the new upper left corner of this   * component.   *   * @param x the new X coordinate of this component   * @param y the new Y coordinate of this component   * @see #getLocation()   * @see #setBounds(int, int, int, int)   */  public void setLocation(int x, int y)  {    move (x, y);  }  /**   * Moves this component to the specified location, relative to the parent's   * coordinates. The coordinates are the new upper left corner of this   * component.   *   * @param x the new X coordinate of this component   * @param y the new Y coordinate of this component   * @deprecated use {@link #setLocation(int, int)} instead   */  public void move(int x, int y)  {    setBounds(x, y, this.width, this.height);  }  /**   * Moves this component to the specified location, relative to the parent's   * coordinates. The coordinates are the new upper left corner of this   * component.   *   * @param p new coordinates for this component   * @throws NullPointerException if p is null   * @see #getLocation()   * @see #setBounds(int, int, int, int)   * @since 1.1   */  public void setLocation(Point p)  {    setLocation(p.x, p.y);  }  /**   * Returns the size of this object.   *   * @return the size of this object   * @see #setSize(int, int)   * @since 1.1   */  public Dimension getSize()  {    return size ();  }  /**   * Returns the size of this object.   *   * @return the size of this object   * @deprecated use {@link #getSize()} instead   */  public Dimension size()  {    return new Dimension (width, height);  }  /**   * Sets the size of this component to the specified width and height.   *   * @param width the new width of this component   * @param height the new height of this component   * @see #getSize()   * @see #setBounds(int, int, int, int)   */  public void setSize(int width, int height)  {    resize (width, height);  }  /**   * Sets the size of this component to the specified value.   *   * @param width the new width of the component   * @param height the new height of the component   * @deprecated use {@link #setSize(int, int)} instead   */  public void resize(int width, int height)  {    setBounds(this.x, this.y, width, height);  }  /**   * Sets the size of this component to the specified value.   *   * @param d the new size of this component   * @throws NullPointerException if d is null   * @see #setSize(int, int)   * @see #setBounds(int, int, int, int)   * @since 1.1   */  public void setSize(Dimension d)  {    resize (d);  }  /**   * Sets the size of this component to the specified value.   *   * @param d the new size of this component   * @throws NullPointerException if d is null   * @deprecated use {@link #setSize(Dimension)} instead   */  public void resize(Dimension d)  {    resize (d.width, d.height);  }  /**   * Returns a bounding rectangle for this component. Note that the   * returned rectange is relative to this component's parent, not to   * the screen.   *   * @return the bounding rectangle for this component   * @see #setBounds(int, int, int, int)   * @see #getLocation()   * @see #getSize()   */  public Rectangle getBounds()  {    return bounds ();  }  /**   * Returns a bounding rectangle for this component. Note that the   * returned rectange is relative to this component's parent, not to   * the screen.   *   * @return the bounding rectangle for this component   * @deprecated use {@link #getBounds()} instead   */  public Rectangle bounds()  {    return new Rectangle (x, y, width, height);  }  /**   * Sets the bounding rectangle for this component to the specified values.   * Note that these coordinates are relative to the parent, not to the screen.   *   * @param x the X coordinate of the upper left corner of the rectangle   * @param y the Y coordinate of the upper left corner of the rectangle   * @param w the width of the rectangle   * @param h the height of the rectangle   * @see #getBounds()   * @see #setLocation(int, int)   * @see #setLocation(Point)   * @see #setSize(int, int)   * @see #setSize(Dimension)   * @since 1.1   */  public void setBounds(int x, int y, int w, int h)  {    reshape (x, y, w, h);  }  /**   * Sets the bounding rectangle for this component to the specified values.   * Note that these coordinates are relative to the parent, not to the screen.   *   * @param x the X coordinate of the upper left corner of the rectangle   * @param y the Y coordinate of the upper left corner of the rectangle   * @param width the width of the rectangle   * @param height the height of the rectangle   * @deprecated use {@link #setBounds(int, int, int, int)} instead   */  public void reshape(int x, int y, int width, int height)  {    int oldx = this.x;    int oldy = this.y;    int oldwidth = this.width;    int oldheight = this.height;    if (this.x == x && this.y == y        && this.width == width && this.height == height)      return;    invalidate ();    this.x = x;    this.y = y;    this.width = width;    this.height = height;    if (peer != null)      peer.setBounds (x, y, width, height);    // Erase old bounds and repaint new bounds for lightweights.    if (isLightweight() && isShowing ())      {        boolean shouldRepaintParent = false;        boolean shouldRepaintSelf = false;        if (parent != null)          {            Rectangle parentBounds = parent.getBounds();            Rectangle oldBounds = new Rectangle(parent.getX() + oldx,                                                parent.getY() + oldy,                                                oldwidth, oldheight);            Rectangle newBounds = new Rectangle(parent.getX() + x,                                                parent.getY() + y,                                                width, height);            shouldRepaintParent = parentBounds.intersects(oldBounds);            shouldRepaintSelf = parentBounds.intersects(newBounds);          }        if (shouldRepaintParent && parent != null)          parent.repaint(oldx, oldy, oldwidth, oldheight);        if (shouldRepaintSelf)          repaint();      }    // Only post event if this component is visible and has changed size.    if (isShowing ()        && (oldx != x || oldy != y))      {        ComponentEvent ce = new ComponentEvent(this,                                               ComponentEvent.COMPONENT_MOVED);        getToolkit().getSystemEventQueue().postEvent(ce);      }    if (isShowing ()        && (oldwidth != width || oldheight != height))      {        ComponentEvent ce = new ComponentEvent(this,                                               ComponentEvent.COMPONENT_RESIZED);        getToolkit().getSystemEventQueue().postEvent(ce);      }  }  /**   * Sets the bounding rectangle for this component to the specified   * rectangle. Note that these coordinates are relative to the parent, not   * to the screen.   *   * @param r the new bounding rectangle   * @throws NullPointerException if r is null   * @see #getBounds()   * @see #setLocation(Point)   * @see #setSize(Dimension)   * @since 1.1

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?