import java.awt.Rectangle; import java.awt.event.MouseEvent; import javax.swing.JComponent; import javax.swing.SwingConstants; import javax.swing.event.MouseInputAdapter; import javax.swing.plaf.metal.MetalScrollBarUI; import javax.swing.plaf.metal.MetalScrollButton; /** * DoubleHeadedScrollbarUI provides the look and feel (i.e., output and input) * for a DoubleHeadedScrollbar, by adding two draggable buttons to the * ends of the thumb. */ public class DoubleHeadedScrollbarUI extends MetalScrollBarUI { /** * Attach this look-and-feel delegate to its component. * Typically creates and adds new subcomponents to c, * attaches listeners, and intializes this delegate. * * @param c scrollbar (must be a DoubleHeadedScrollbar) that * this delegate will be handling input and output * for. */ public void installUI(JComponent c) { super.installUI(c); // here's how to create a left-pointing arrow button: // new MetalScrollButton(SwingConstants.WEST, scrollBarWidth, true); } /** * Called to set the bounding rectangle of the scroll thumb. * We override it here because we need to position buttons * on top of the thumb. *
* When the thumb is as big as the scrollbar, this method * is called with (0,0,0,0). * * @param x left edge of thumb, relative to scrollbar's coordinate system * @param y top edge of thumb, relative to scrollbar's coordinate system * @param width width of thumb in pixels * @param height height of thumb in pixels */ protected void setThumbBounds(int x, int y, int width, int height) { super.setThumbBounds(x, y, width, height); // your code here } }