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); } }
protected void layoutHScrollbar(JScrollBar sb) { if (useAlternateLayout) alternateLayoutHScrollbar(sb); else super.layoutHScrollbar(sb); }