I want to make a custom scroll bar that looks like this in my java application:
I found this answer, and it seems to work, but I don't know how to implement graphics.
I've been making some test on my own but none of them seemed to work. Any leads on how to use graphics to make a custom scrollbar?
I tried to implement the following code, but there are 3 problems, the windows scrollbar stills showing up, the graphics that I made are transparent, and the thumb is not moving
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;
import javax.swing.JComponent;
import javax.swing.plaf.basic.BasicScrollBarUI;
public class MyScrollBarUI extends BasicScrollBarUI{
@Override
protected void paintTrack(Graphics g, JComponent c, Rectangle trackBounds) {
g.setColor(new Color(33, 31, 32));
g.drawRoundRect(0, 0, 10, 550, 5, 5);
}
@Override
protected void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds) {
g.setColor(new Color(237, 24, 33));
g.drawRoundRect(0, 0, 10, 60, 5, 5);
}
}
This is the result: scrollbar2