Say I have an appropriately sized image inside an Image()
I want to change the Thumb or Knob of the JScrollBar
component to be this image.
I know I need to subclass the ScrollBarUI
Here is where I am at right now.
public class aScrollBar extends JScrollBar {
public aScrollBar(Image img) {
super();
this.setUI(new ScrollBarCustomUI(img));
}
public class ScrollBarCustomUI extends BasicScrollBarUI {
private final Image image;
public ScrollBarCustomUI(Image img) {
this.image = img;
}
@Override
protected void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds) {
Graphics2D g2g = (Graphics2D) g;
g2g.dispose();
g2g.drawImage(image, 0, 0, null);
super.paintThumb(g2g, c, thumbBounds);
}
@Override
protected void paintTrack(Graphics g, JComponent c, Rectangle trackBounds) {
super.paintTrack(g, c, trackBounds);
}
@Override
protected void setThumbBounds(int x, int y, int width, int height) {
super.setThumbBounds(0, 0, 0, 0);
}
@Override
protected Dimension getMinimumThumbSize() {
return new Dimension(0, 0);
}
@Override
protected Dimension getMaximumThumbSize() {
return new Dimension(0, 0);
}
}
}
Right now I don't see any Thumb, only a Track when I try to click around the ScrollBar.
I checked out this article and saw people recommended you read this but nowhere does he mention images so this is what I came up with.
Hopefully someone can help me, Thanks!