コード例 #1
0
  protected void installDefaults() {
    super.installDefaults();

    scrollBarWidth = UIManager.getInt("ScrollBar.width");
    incrGap = UIManager.getInt("ScrollBar.incrementButtonGap");
    decrGap = UIManager.getInt("ScrollBar.decrementButtonGap");

    // TODO this can be removed when incrGap/decrGap become protected
    // handle scaling for sizeVarients for special case components. The
    // key "JComponent.sizeVariant" scales for large/small/mini
    // components are based on Apples LAF
    String scaleKey = (String) scrollbar.getClientProperty("JComponent.sizeVariant");
    if (scaleKey != null) {
      if ("large".equals(scaleKey)) {
        scrollBarWidth *= 1.15;
        incrGap *= 1.15;
        decrGap *= 1.15;
      } else if ("small".equals(scaleKey)) {
        scrollBarWidth *= 0.857;
        incrGap *= 0.857;
        decrGap *= 0.857;
      } else if ("mini".equals(scaleKey)) {
        scrollBarWidth *= 0.714;
        incrGap *= 0.714;
        decrGap *= 0.714;
      }
    }
  }
コード例 #2
0
 /** Installs the defaults. */
 protected void installDefaults() {
   // need to initialise isFreeStanding before calling the super class,
   // so that the value is set when createIncreaseButton() and
   // createDecreaseButton() are called (unless there is somewhere earlier
   // that we can do this).
   Boolean prop = (Boolean) scrollbar.getClientProperty(FREE_STANDING_PROP);
   isFreeStanding = prop == null ? true : prop.booleanValue();
   scrollBarShadowColor = UIManager.getColor("ScrollBar.shadow");
   super.installDefaults();
 }
コード例 #3
0
ファイル: NewScrollBarUI.java プロジェクト: sigh0829/IMClient
  // 重绘滚动条的滑块
  public void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds) {
    super.paintThumb(g, c, thumbBounds);
    int tw = thumbBounds.width;
    int th = thumbBounds.height;
    // 重定图形上下文的原点,这句一定要写,不然会出现拖动滑块时滑块不动的现象
    g.translate(thumbBounds.x, thumbBounds.y);

    Graphics2D g2 = (Graphics2D) g;
    GradientPaint gp = null;
    if (this.scrollbar.getOrientation() == JScrollBar.VERTICAL) {
      gp = new GradientPaint(0, 0, new Color(204, 204, 204), tw, 0, new Color(204, 204, 204));
    }
    if (this.scrollbar.getOrientation() == JScrollBar.HORIZONTAL) {
      gp = new GradientPaint(0, 0, new Color(204, 204, 204), 0, th, new Color(204, 204, 204));
    }
    g2.setPaint(gp);
    g2.fillRoundRect(0, 0, (tw - 1), (th - 1), 5, 5);
    // 边框颜色
    g2.setColor(thumbBorderColor);
    g2.drawRoundRect(0, 0, (tw - 1), (th - 1), 5, 5);
  }
コード例 #4
0
  protected void layoutHScrollbar(JScrollBar sb) {
    if (AbstractLookAndFeel.getTheme().isLinuxStyleScrollBarOn()) {
      Dimension sbSize = sb.getSize();
      Insets sbInsets = sb.getInsets();
      int sizeW = sbSize.width - sbInsets.left - sbInsets.right;

      /*
       * Height and top edge of the buttons and thumb.
       */
      int itemY = sbInsets.top;
      int itemH = sbSize.height - (sbInsets.top + sbInsets.bottom); // Math.min(itemW, sizeH / 2);
      int itemW = Math.min(itemH, sizeW / 2); // sbSize.width - (sbInsets.left + sbInsets.right);

      /* Nominal locations of the buttons, assuming their preferred
       * size will fit.
       */
      int decrButtonX = sbSize.width - sbInsets.right - itemW - itemW + 1;
      int incrButtonX = sbSize.width - sbInsets.right - itemW;

      /* Compute the width and origin of the thumb. The case
       * where the thumb is at the right edge is handled specially
       * to avoid numerical problems in computing thumbX.  Enforce
       * the thumbs min/max dimensions. If the thumb doesn't
       * fit in the track (trackW) we'll hide it later.
       */
      float trackW = sbSize.width - sbInsets.left - sbInsets.right - itemH - itemH + 1;
      float min = sb.getMinimum();
      float max = sb.getMaximum();
      float extent = sb.getVisibleAmount();
      float range = max - min;
      float value = sb.getValue();

      int maxThumbW = getMaximumThumbSize().width;
      int minThumbW = getMinimumThumbSize().width;
      int thumbW = (range <= 0) ? maxThumbW : (int) (trackW * (extent / range));
      thumbW = Math.max(thumbW, minThumbW);
      thumbW = Math.min(thumbW, maxThumbW);

      int thumbX = decrButtonX - thumbW;
      if (value < (max - extent)) {
        float thumbRange = trackW - thumbW;
        thumbX = (int) (0.5f + (thumbRange * ((value - min) / (range - extent))));
      }

      /* If the thumb isn't going to fit, zero it's bounds.  Otherwise
       * make sure it fits between the buttons.  Note that setting the
       * thumbs bounds will cause a repaint.
       */
      if (thumbW > trackW) {
        setThumbBounds(0, 0, 0, 0);
      } else {
        setThumbBounds(thumbX, itemY, thumbW, itemH);
      }
      decrButton.setBounds(decrButtonX, itemY, itemW, itemH);
      incrButton.setBounds(incrButtonX, itemY, itemW, itemH);

      /* Update the trackRect field.
       */
      trackRect.setBounds(0, itemY, (int) trackW, itemH);

    } else {
      super.layoutHScrollbar(sb);
    }
  }
コード例 #5
0
 protected void layoutVScrollbar(JScrollBar sb) {
   if (useAlternateLayout) alternateLayoutVScrollbar(sb);
   else super.layoutVScrollbar(sb);
 }
コード例 #6
0
 public void setThumbBounds(int x, int y, int w, int h) {
   super.setThumbBounds(x, y, w, h);
 }
コード例 #7
0
ファイル: NewScrollBarUI.java プロジェクト: sigh0829/IMClient
 // 设置滑块bounds
 @Override
 protected void setThumbBounds(int x, int y, int width, int height) {
   super.setThumbBounds(x + width / 4, y, width / 2, height);
 }
コード例 #8
0
 /*
  * @see javax.swing.plaf.basic.BasicScrollBarUI#paint(java.awt.Graphics,
  * javax.swing.JComponent)
  */
 @Override
 public void paint(Graphics g, JComponent c) {
   super.paint(g, c);
 }