我正在尝试使用下面的代码自定义 jScrollPane。它有效,它以我想要的方式改变颜色,但隐藏了箭头按钮。
我想要的是让它们再次可见并用自定义图像更改它们。我试着在这个论坛上搜索,但我找不到任何关于它的信息。
我希望有一个人可以帮助我。提前致谢!
private Image imageThumb, imageTrack;
private JButton b = new JButton() {
@Override
public Dimension getPreferredSize() {
return new Dimension(0, 0);
}
};
public YourScrollbarUI () {
imageThumb = WrapImage .create(45, 45, new Color(46,218,163));
imageTrack = WrapImage .create(32, 32, new Color(90,90,90));
}
@Override
protected void paintThumb(Graphics g, JComponent c, Rectangle r) {
g.setColor(Color.blue);
((Graphics2D) g).drawImage(imageThumb,
r.x, r.y, r.width, r.height, null);
}
@Override
protected void paintTrack(Graphics g, JComponent c, Rectangle r) {
((Graphics2D) g).drawImage(imageTrack,
r.x, r.y, r.width, r.height, null);
}
@Override
protected JButton createDecreaseButton(int orientation) {
return b;
}
@Override
protected JButton createIncreaseButton(int orientation) {
return b;
}
private static class WrapImage {
static public Image create(int w, int h, Color c) {
BufferedImage bi = new BufferedImage(
w, h, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = bi.createGraphics();
g2d.setPaint(c);
g2d.fillRect(0, 0, w, h);
g2d.dispose();
return bi;}}