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

📄 jlist.java

📁 gcc的组建
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
   *   * @param ui The new property value   */  public void setUI(ListUI ui)  {    super.setUI(ui);  }  /**   * Calls {@link #setUI} with the {@link ListUI} subclass   * returned from calling {@link UIManager#getUI}.   */  public void updateUI()  {    setUI((ListUI) UIManager.getUI(this));  }  /**   * Return the class identifier for the list's UI property.  This should   * be the constant string <code>"ListUI"</code>, and map to an   * appropriate UI class in the {@link UIManager}.   *   * @return The class identifier   */  public String getUIClassID()  {    return "ListUI";  }  /**   * Returns the current value of the {@link #prototypeCellValue}   * property. This property holds a reference to a "prototype" data value   * -- typically a String -- which is used to calculate the {@link   * #fixedCellWidth} and {@link #fixedCellHeight} properties, using the   * {@link #cellRenderer} property to acquire a component to render the   * prototype.   *   * @return The current prototype cell value   * @see #setPrototypeCellValue   */  public Object getPrototypeCellValue()  {    return prototypeCellValue;  }  /**   * <p>Set the {@link #prototypeCellValue} property. This property holds a   * reference to a "prototype" data value -- typically a String -- which   * is used to calculate the {@link #fixedCellWidth} and {@link   * #fixedCellHeight} properties, using the {@link #cellRenderer} property   * to acquire a component to render the prototype.</p>   *   * <p>It is important that you <em>not</em> set this value to a   * component. It has to be a <em>data value</em> such as the objects you   * would find in the list's model. Setting it to a component will have   * undefined (and undesirable) affects. </p>   *   * @param obj The new prototype cell value   * @see #getPrototypeCellValue   */  public void setPrototypeCellValue(Object obj)  {    if (prototypeCellValue == obj)      return;    Object old = prototypeCellValue;    Component comp = getCellRenderer()      .getListCellRendererComponent(this, obj, 0, false, false);     Dimension d = comp.getPreferredSize();    fixedCellWidth = d.width;    fixedCellHeight = d.height;    prototypeCellValue = obj;    firePropertyChange("prototypeCellValue", old, obj);  }  public AccessibleContext getAccessibleContext()  {    return new AccessibleJList();  }  /**   * Returns a size indicating how much space this list would like to   * consume, when contained in a scrollable viewport. This is part of the   * {@link Scrollable} interface, which interacts with {@link   * ScrollPaneLayout} and {@link JViewport} to define scrollable objects.   *   * @return The preferred size   */  public Dimension getPreferredScrollableViewportSize()  {    //If the layout orientation is not VERTICAL, then this will     //return the value from getPreferredSize. The current ListUI is     //expected to override getPreferredSize to return an appropriate value.    if (getLayoutOrientation() != VERTICAL)      return getPreferredSize();            int size = getModel().getSize();        // Trivial case: if fixedCellWidth and fixedCellHeight were set     // just use them    if (fixedCellHeight != -1 && fixedCellWidth != -1)      return new Dimension(fixedCellWidth, size * fixedCellHeight);            // If the model is empty we use 16 * the number of visible rows    // for the height and either fixedCellWidth (if set) or 256    // for the width    if (size == 0)      {        if (fixedCellWidth == -1)          return new Dimension(256, 16 * getVisibleRowCount());        else          return new Dimension(fixedCellWidth, 16 * getVisibleRowCount());      }    // Calculate the width: if fixedCellWidth was set use that, otherwise    // use the preferredWidth    int prefWidth;    if (fixedCellWidth != -1)      prefWidth = fixedCellWidth;    else      prefWidth = getPreferredSize().width;    // Calculate the height: if fixedCellHeight was set use that, otherwise    // use the height of the first row multiplied by the number of visible    // rows    int prefHeight;    if (fixedCellHeight != -1)      prefHeight = fixedCellHeight;    else      prefHeight = getVisibleRowCount() * getCellBounds(0, 0).height;    return new Dimension (prefWidth, prefHeight);  }  /**   * <p>Return the number of pixels the list must scroll in order to move a   * "unit" of the list into the provided visible rectangle. When the   * provided direction is positive, the call describes a "downwards"   * scroll, which will be exposing a cell at a <em>greater</em> index in   * the list than those elements currently showing. Then the provided   * direction is negative, the call describes an "upwards" scroll, which   * will be exposing a cell at a <em>lesser</em> index in the list than   * those elements currently showing.</p>   *   * <p>If the provided orientation is <code>HORIZONTAL</code>, the above   * comments refer to "rightwards" for positive direction, and "leftwards"   * for negative.</p>   *    *   * @param visibleRect The rectangle to scroll an element into   * @param orientation One of the numeric consants <code>VERTICAL</code>   * or <code>HORIZONTAL</code>   * @param direction An integer indicating the scroll direction: positive means   * forwards (down, right), negative means backwards (up, left)   *   * @return The scrollable unit increment, in pixels   */  public int getScrollableUnitIncrement(Rectangle visibleRect,                                        int orientation, int direction)  {    ListUI lui = this.getUI();    if (orientation == SwingConstants.VERTICAL)      {        if (direction > 0)          {            // Scrolling down            Point bottomLeft = new Point(visibleRect.x,                                         visibleRect.y + visibleRect.height);            int curIdx = lui.locationToIndex(this, bottomLeft);            Rectangle curBounds = lui.getCellBounds(this, curIdx, curIdx);            if (curBounds.y + curBounds.height == bottomLeft.y)              {                // we are at the exact bottom of the current cell, so we                 // are being asked to scroll to the end of the next one                if (curIdx + 1 < model.getSize())                  {                    // there *is* a next item in the list                    Rectangle nxtBounds = lui.getCellBounds(this, curIdx + 1, curIdx + 1);                    return nxtBounds.height;                  }                else                  {                    // no next item, no advance possible                    return 0;                  }              }            else              {                // we are part way through an existing cell, so we are being                // asked to scroll to the bottom of it                return (curBounds.y + curBounds.height) - bottomLeft.y;              }		                }        else          {            // scrolling up            Point topLeft = new Point(visibleRect.x, visibleRect.y);            int curIdx = lui.locationToIndex(this, topLeft);            Rectangle curBounds = lui.getCellBounds(this, curIdx, curIdx);            if (curBounds.y == topLeft.y)              {                // we are at the exact top of the current cell, so we                 // are being asked to scroll to the top of the previous one                if (curIdx > 0)                  {                    // there *is* a previous item in the list                    Rectangle nxtBounds = lui.getCellBounds(this, curIdx - 1, curIdx - 1);                    return -nxtBounds.height;                  }                else                  {                    // no previous item, no advance possible                    return 0;                  }              }            else              {                // we are part way through an existing cell, so we are being                // asked to scroll to the top of it                return curBounds.y - topLeft.y;              }		                }      }    // FIXME: handle horizontal scrolling (also wrapping?)    return 1;  }  /**   * <p>Return the number of pixels the list must scroll in order to move a   * "block" of the list into the provided visible rectangle. When the   * provided direction is positive, the call describes a "downwards"   * scroll, which will be exposing a cell at a <em>greater</em> index in   * the list than those elements currently showing. Then the provided   * direction is negative, the call describes an "upwards" scroll, which   * will be exposing a cell at a <em>lesser</em> index in the list than   * those elements currently showing.</p>   *   * <p>If the provided orientation is <code>HORIZONTAL</code>, the above   * comments refer to "rightwards" for positive direction, and "leftwards"   * for negative.</p>   *    *   * @param visibleRect The rectangle to scroll an element into   * @param orientation One of the numeric consants <code>VERTICAL</code>   * or <code>HORIZONTAL</code>   * @param direction An integer indicating the scroll direction: positive means   * forwards (down, right), negative means backwards (up, left)   *   * @return The scrollable unit increment, in pixels   */  public int getScrollableBlockIncrement(Rectangle visibleRect,                                         int orientation, int direction)  {      if (orientation == VERTICAL)	  return visibleRect.height * direction;      else	  return visibleRect.width * direction;  }  /**   * Gets the value of the <code>scrollableTracksViewportWidth</code> property.   *   * @return <code>true</code> if the viewport is larger (horizontally)   * than the list and the list should be expanded to fit the viewport;   * <code>false</code> if the viewport is smaller than the list and the   * list should scroll (horizontally) within the viewport   */  public boolean getScrollableTracksViewportWidth()  {    Component parent = getParent();    boolean retVal = false;    if (parent instanceof JViewport)      {        JViewport viewport = (JViewport) parent;        Dimension pref = getPreferredSize();        if (viewport.getSize().width > pref.width)          retVal = true;        if ((getLayoutOrientation() == HORIZONTAL_WRAP)            && (getVisibleRowCount() <= 0))          retVal = true;      }    return retVal;  }  /**   * Gets the value of the </code>scrollableTracksViewportWidth</code> property.   *   * @return <code>true</code> if the viewport is larger (vertically)   * than the list and the list should be expanded to fit the viewport;   * <code>false</code> if the viewport is smaller than the list and the   * list should scroll (vertically) within the viewport   */  public boolean getScrollableTracksViewportHeight()  {    Component parent = getParent();    boolean retVal = false;    if (parent instanceof JViewport)      {        JViewport viewport = (JViewport) parent;        Dimension pref = getPreferredSize();        if (viewport.getSize().height > pref.height)          retVal = true;        if ((getLayoutOrientation() == VERTICAL_WRAP)            && (getVisibleRowCount() <= 0))          retVal = true;      }    return retVal;  }  public int getAnchorSelectionIndex()  {    return selectionModel.getAnchorSelectionIndex();  }  public int getLeadSelectionIndex()  {    return selectionModel.getLeadSelectionIndex();  }  public int getMinSelectionIndex()  {    return selectionModel.getMaxSelectionIndex();  }  public int getMaxSelectionIndex()  {    return selectionModel.getMaxSelectionIndex();  }  public void clearSelection()  {    selectionModel.clearSelection();  }  public void setSelectionInterval(int anchor, int lead)  {    selectionModel.setSelectionInterval(anchor, lead);  }  public void addSelectionInterval(int anchor, int lead)  {    selectionModel.addSelectionInterval(anchor, lead);  }  public void removeSelectionInterval(int index0, int index1)  {    selectionModel.removeSelectionInterval(index0, index1);  }  /**   * Returns the value of the <code>valueIsAdjusting</code> property.   *   * @return the value   */  public boolean getValueIsAdjusting()  {    return valueIsAdjusting;  }  /**   * Sets the <code>valueIsAdjusting</code> property.   *   * @param isAdjusting the new value   */  public void setValueIsAdjusting(boolean isAdjusting)  {    valueIsAdjusting = isAdjusting;  }  /**   * Return the value of the <code>dragEnabled</code> property.   *   * @return the value   *    * @since 1.4   */  public boolean getDragEnabled()  {    return dragEnabled;  }  /**   * Set the <code>dragEnabled</code> property.   *   * @param enabled new value   *    * @since 1.4   */  public void setDragEnabled(boolean enabled)  {    dragEnabled = enabled;  }  /**   * Returns the layout orientation.   *   * @return the orientation, one of <code>JList.VERTICAL</code>,   * <code>JList.VERTICAL_WRAP</code> and <code>JList.HORIZONTAL_WRAP</code>   *   * @since 1.4   */  public int getLayoutOrientation()  {    return layoutOrientation;  }  /**   * Sets the layout orientation.   *   * @param orientation the orientation to set, one of <code>JList.VERTICAL</code>,   * <code>JList.VERTICAL_WRAP</code> and <code>JList.HORIZONTAL_WRAP</code>   *   * @since 1.4   */  public void setLayoutOrientation(int orientation)  {    if (layoutOrientation == orientation)      return;    int old = layoutOrientation;    layoutOrientatio

⌨️ 快捷键说明

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