⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jcomponent.java

📁 gcc的组建
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
  /**   * Get the component's preferred size. If the {@link #preferredSize}   * property has been explicitly set, it is returned. If the {@link   * #preferredSize} property has not been set but the {@link #ui} property   * has been, the result of {@link ComponentUI#getPreferredSize} is   * returned. If neither property has been set, the result of {@link   * Container#getPreferredSize} is returned.   *   * @return The preferred size of the component   *   * @see #preferredSize   * @see #setPreferredSize   */  public Dimension getPreferredSize()  {    Dimension prefSize = null;    if (preferredSize != null)      prefSize = preferredSize;    else if (ui != null)      {        Dimension s = ui.getPreferredSize(this);        if (s != null)          prefSize = s;      }    if (prefSize == null)      prefSize = super.getPreferredSize();    // make sure that prefSize is not smaller than minSize    if (minimumSize != null && prefSize != null        && (minimumSize.width > prefSize.width            || minimumSize.height > prefSize.height))        prefSize = new Dimension(Math.max(minimumSize.width, prefSize.width),                                 Math.max(minimumSize.height, prefSize.height));    return prefSize;  }  /**   * Checks if a maximum size was explicitely set on the component.   *   * @return <code>true</code> if a maximum size was set,   * <code>false</code> otherwise   *    * @since 1.3   */  public boolean isMaximumSizeSet()  {    return maximumSize != null;  }  /**   * Checks if a minimum size was explicitely set on the component.   *   * @return <code>true</code> if a minimum size was set,   * <code>false</code> otherwise   *    * @since 1.3   */  public boolean isMinimumSizeSet()  {    return minimumSize != null;  }  /**   * Checks if a preferred size was explicitely set on the component.   *   * @return <code>true</code> if a preferred size was set,   * <code>false</code> otherwise   *    * @since 1.3   */  public boolean isPreferredSizeSet()  {    return preferredSize != null;  }    /**   * Return the value of the <code>nextFocusableComponent</code> property.   *   * @return The current value of the property, or <code>null</code>   * if none has been set.   *    * @deprecated See {@link java.awt.FocusTraversalPolicy}   */  public Component getNextFocusableComponent()  {    return null;  }  /**   * Return the set of {@link KeyStroke} objects which are registered   * to initiate actions on this component.   *   * @return An array of the registered keystrokes   */  public KeyStroke[] getRegisteredKeyStrokes()  {    return null;  }  /**   * Returns the first ancestor of this component which is a {@link JRootPane}.   * Equivalent to calling <code>SwingUtilities.getRootPane(this);</code>.   *   * @return An ancestral JRootPane, or <code>null</code> if none exists.   */  public JRootPane getRootPane()  {    JRootPane p = SwingUtilities.getRootPane(this);    return p;  }  /**   * Get the component's size. The passed-in {@link Dimension} value   * will be used as the return value, if possible.   *   * @param rv Return value object to reuse, if possible   *   * @return The component's current size   */  public Dimension getSize(Dimension rv)  {    if (rv == null)      return new Dimension(getWidth(), getHeight());    else      {        rv.setSize(getWidth(), getHeight());        return rv;      }  }  /**   * Return the <code>toolTip</code> property of this component, creating it and   * setting it if it is currently <code>null</code>. This method can be   * overridden in subclasses which wish to control the exact form of   * tooltip created.   *   * @return The current toolTip   */  public JToolTip createToolTip()  {    JToolTip toolTip = new JToolTip();    toolTip.setComponent(this);    toolTip.setTipText(toolTipText);    return toolTip;  }  /**   * Return the location at which the {@link #toolTipText} property should be   * displayed, when triggered by a particular mouse event.    *   * @param event The event the tooltip is being presented in response to   *   * @return The point at which to display a tooltip, or <code>null</code>   *     if swing is to choose a default location.   */  public Point getToolTipLocation(MouseEvent event)  {    return null;  }  /**   * Set the value of the {@link #toolTipText} property.   *   * @param text The new property value   *   * @see #getToolTipText()   */  public void setToolTipText(String text)  {    if (text == null)    {      ToolTipManager.sharedInstance().unregisterComponent(this);      toolTipText = null;      return;    }    // XXX: The tip text doesn't get updated unless you set it to null    // and then to something not-null. This is consistent with the behaviour    // of Sun's ToolTipManager.    String oldText = toolTipText;    toolTipText = text;    if (oldText == null)      ToolTipManager.sharedInstance().registerComponent(this);  }  /**   * Get the value of the {@link #toolTipText} property.   *   * @return The current property value   *   * @see #setToolTipText   */  public String getToolTipText()  {    return toolTipText;  }  /**   * Get the value of the {@link #toolTipText} property, in response to a   * particular mouse event.   *   * @param event The mouse event which triggered the tooltip   *   * @return The current property value   *   * @see #setToolTipText   */  public String getToolTipText(MouseEvent event)  {    return getToolTipText();  }  /**   * Return the top level ancestral container (usually a {@link   * java.awt.Window} or {@link java.applet.Applet}) which this component is   * contained within, or <code>null</code> if no ancestors exist.   *   * @return The top level container, if it exists   */  public Container getTopLevelAncestor()  {    Container c = getParent();    for (Container peek = c; peek != null; peek = peek.getParent())      c = peek;    return c;  }  /**   * Compute the component's visible rectangle, which is defined   * recursively as either the component's bounds, if it has no parent, or   * the intersection of the component's bounds with the visible rectangle   * of its parent.   *   * @param rect The return value slot to place the visible rectangle in   */  public void computeVisibleRect(Rectangle rect)  {    Component c = getParent();    if (c != null && c instanceof JComponent)      {        ((JComponent) c).computeVisibleRect(rect);        rect.translate(-getX(), -getY());        Rectangle2D.intersect(rect,                              new Rectangle(0, 0, getWidth(), getHeight()),                              rect);      }    else      rect.setRect(0, 0, getWidth(), getHeight());  }  /**   * Return the component's visible rectangle in a new {@link Rectangle},   * rather than via a return slot.   *   * @return The component's visible rectangle   *   * @see #computeVisibleRect(Rectangle)   */  public Rectangle getVisibleRect()  {    Rectangle r = new Rectangle();    computeVisibleRect(r);    return r;  }  /**   * <p>Requests that this component receive input focus, giving window   * focus to the top level ancestor of this component. Only works on   * displayable, focusable, visible components.</p>   *   * <p>This method should not be called by clients; it is intended for   * focus implementations. Use {@link Component#requestFocus()} instead.</p>   *   * @see Component#requestFocus()   */  public void grabFocus()  {    // TODO: Implement this properly.  }  /**   * Get the value of the {@link #doubleBuffered} property.   *   * @return The property's current value   */  public boolean isDoubleBuffered()  {    return doubleBuffered;  }  /**   * Return <code>true</code> if the provided component has no native peer;   * in other words, if it is a "lightweight component".   *   * @param c The component to test for lightweight-ness   *   * @return Whether or not the component is lightweight   */  public static boolean isLightweightComponent(Component c)  {    return c.getPeer() instanceof LightweightPeer;  }  /**   * Return <code>true</code> if you wish this component to manage its own   * focus. In particular: if you want this component to be sent   * <code>TAB</code> and <code>SHIFT+TAB</code> key events, and to not   * have its children considered as focus transfer targets. If   * <code>true</code>, focus traversal around this component changes to   * <code>CTRL+TAB</code> and <code>CTRL+SHIFT+TAB</code>.   *   * @return <code>true</code> if you want this component to manage its own   *     focus, otherwise (by default) <code>false</code>   *   * @deprecated 1.4 Use {@link Component#setFocusTraversalKeys(int, Set)} and   *     {@link Container#setFocusCycleRoot(boolean)} instead   */  public boolean isManagingFocus()  {    return false;  }  /**   * Return the current value of the {@link #opaque} property.    *   * @return The current property value   */  public boolean isOpaque()  {    return opaque;  }  /**   * Return <code>true</code> if the component can guarantee that none of its   * children will overlap in Z-order. This is a hint to the painting system.   * The default is to return <code>true</code>, but some components such as   * {@link JLayeredPane} should override this to return <code>false</code>.   *   * @return Whether the component tiles its children   */  public boolean isOptimizedDrawingEnabled()  {    return true;  }  /**   * Return <code>true</code> if this component is currently painting a tile,   * this means that paint() is called again on another child component. This   * method returns <code>false</code> if this component does not paint a tile   * or if the last tile is currently painted.   *   * @return whether the component is painting a tile   */  public boolean isPaintingTile()  {    return paintingTile;  }  /**   * Get the value of the {@link #requestFocusEnabled} property.   *   * @return The current value of the property   */  public boolean isRequestFocusEnabled()  {    return requestFocusEnabled;  }  /**   * Return <code>true</code> if this component is a validation root; this   * will cause calls to {@link #invalidate()} in this component's children   * to be "captured" at this component, and not propagate to its parents.   * For most components this should return <code>false</code>, but some   * components such as {@link JViewport} will want to return   * <code>true</code>.   *   * @return Whether this component is a validation root   */  public boolean isValidateRoot()  {    return false;  }  /**   * <p>Paint the component. This is a delicate process, and should only be   * called from the repaint thread, under control of the {@link   * RepaintManager}. Client code should usually call {@link #repaint()} to   * trigger painting.</p>   *   * <p>The body of the <code>paint</code> call involves calling {@link   * #paintComponent}, {@link #paintBorder}, and {@link #paintChildren} in   * order. If you want to customize painting behavior, you should override   * one of these methods rather than <code>paint</code>.</p>   *   * <p>For more details on the painting sequence, see <a   * href="http://java.sun.com/products/jfc/tsc/articles/painting/index.html">   * this article</a>.</p>   *   * @param g The graphics context to paint with   *   * @see #paintImmediately(Rectangle)   */  public void paint(Graphics g)  {    RepaintManager rm = RepaintManager.currentManager(this);    // We do a little stunt act here to switch on double buffering if it's    // not already on. If we are not already doublebuffered, then we jump    // into the method paintDoubleBuffered, which turns on the double buffer    // and then calls paint(g) again. In the second call we go into the else    // branch of this if statement and actually paint things to the double    // buffer. When this method completes, the call stack unwinds back to    // paintDoubleBuffered, where the buffer contents is finally drawn to the    // screen.    if (!isPaintingDoubleBuffered && isDoubleBuffered()        && rm.isDoubleBufferingEnabled())      paintDoubleBuffered(g);    else      {        if (g.getClip() == null)          g.setClip(0, 0, getWidth(), getHeight());

⌨️ 快捷键说明

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