Custom JScrollbar Problem (change the knob/thumb)
<p>I want to change the look of a JScrollBar.<br>
I do this with overwriting/extending ScrollBarUI.<br>
It´s no problem to change the outlook of the arrowbuttons by overwriting <code>createIncreaseButton</code> and <code>createDecreaseButton</code>.
I change the width of the track by overwriting paintThumb and paintTrack Methods.</p>

<p>It looks now like <code>&lt;----o----&gt;</code> (a very thin trackline and an oval thumb/knob).<br>
<strong>PROBLEM:</strong><br>
The knob can't move till the very end:<br>
What it does look like: &nbsp;&nbsp;  <code>&lt;---o------&gt;</code><br>
What it should look like: <code>&lt;---------o&gt;</code>  </p>

<p>I know this is because I made the oval not stretching (the original rectangle stretches with the width).<br>
I'm totally clueless as were to change the computing of the thumb move so it can move until the end.</p>

<p>I would be very thankful for help.</p>

<p>Heres the code:</p>

<pre><code>public class TestScrollBarMain extends JFrame {

public TestScrollBarMain() {
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    JPanel p = new JPanel();
    p.setPreferredSize(new Dimension(500, 500));
    JScrollPane s = new JScrollPane(p);
    MyScrollBar b = new MyScrollBar();
    s.setVerticalScrollBar(b);
    getContentPane().add(s);
    setSize(100, 100);
    setVisible(true);
}

public static void main(String[] args) {
    new TestScrollBarMain();
}

public class MyScrollBarUI extends BasicScrollBarUI {

    @Override
    protected void paintThumb(final Graphics g, final JComponent c, final Rectangle thumbBounds) {
        if (thumbBounds.isEmpty() || !this.scrollbar.isEnabled()) {
            return;
        }
        g.translate(thumbBounds.x, thumbBounds.y);
        g.setColor(this.thumbDarkShadowColor);
        g.drawOval(2, 0, 14, 14);
        g.setColor(this.thumbColor);
        g.fillOval(2, 0, 14, 14);
        g.setColor(this.thumbHighlightColor);
        g.setColor(this.thumbLightShadowColor);
        g.translate(-thumbBounds.x, -thumbBounds.y);
    }

    @Override
    protected void paintTrack(final Graphics g, final JComponent c, final Rectangle trackBounds) {
        g.setColor(Color.black);
        g.fillRect(trackBounds.width / 2, trackBounds.y, 3, trackBounds.height);
        if (this.trackHighlight == BasicScrollBarUI.DECREASE_HIGHLIGHT) {
            this.paintDecreaseHighlight(g);
        } else if (this.trackHighlight == BasicScrollBarUI.INCREASE_HIGHLIGHT) {
            this.paintIncreaseHighlight(g);
        }
    }
}

public class MyScrollBar extends JScrollBar {

    MyScrollBar() {
        super();
        setUI(new MyScrollBarUI());
    }
}

}
</code></pre>
