自定义JScrollbar问题(更改旋钮/拇指)

我想改变JScrollBar的外观。
我这样做是为了覆盖/扩展ScrollBarUI。
通过覆盖createIncreaseButtoncreateDecreaseButton来改变箭头按钮的外观没有问题。 我通过覆盖paintThumb和paintTrack方法来改变轨道的宽度。

现在看起来像是 (非常薄的轨迹线和椭圆形的拇指/旋钮)。
问题:
旋钮直到最后才能移动:
它看起来像什么:
应该是什么样的:

我知道这是因为我使椭圆形不拉伸(原始矩形随宽度延伸)。
我完全无能为力,因为它改变了拇指移动的计算,所以它可以移动到最后。

我非常感谢你的帮助。

inheritance人代码:

 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()); } } } 

将其包含在MyScrollBarUI代码中:

  protected void setThumbBounds(int x, int y,int width,int height) { super.setThumbBounds(x, y, 14, 14); } protected Rectangle getThumbBounds() { return new Rectangle(super.getThumbBounds().x,super.getThumbBounds().y,14,14); } protected Dimension getMinimumThumbSize() { return new Dimension(14,14); } protected Dimension getMaximumThumbSize() { return new Dimension(14,14); }