Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the color of Scrollbar in JScrollPane?

Tags:

java

swing

I want to change the JScrollPane Scrollbar color to black. I tried to make the change using UIManger. but found nothing.

like image 687
Harshad201 Avatar asked Dec 08 '25 09:12

Harshad201


1 Answers

To change the background color of the scroll bar, you can do this:

scrollPane.getVerticalScrollBar().setBackground(Color.BLACK);
scrollPane.getHorizontalScrollBar().setBackground(Color.BLACK);

To change the color of the scrollbar itself, use the following code:

import javax.swing.plaf.basic.BasicScrollBarUI;

scrollPane.getVerticalScrollBar().setUI(new BasicScrollBarUI() {
    @Override
    protected void configureScrollBarColors() {
        this.thumbColor = Color.BLACK;
    }
});
like image 63
Julian Peffer Avatar answered Dec 10 '25 22:12

Julian Peffer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!