1

I know this question has been asked before, but none of the solutions found seem to work for me. So I have a JScrollPane with a JTable attached to it and I am trying to change those ugly default scrollbar thumb colours. Thumb is referring to the actual button/slider that you move to scroll.

I have tried using the UIManager but to no avail. I'm using Eclipse by the way. How would I go about fixing this issue? If anyone has an answer that they can explain well then that would be great.

camickr
  • 321,443
  • 19
  • 166
  • 288

1 Answers1

3

Use this:

UIManager.put("ScrollBar.thumb", new ColorUIResource(Color.RED));

pictureScrollPane.getVerticalScrollBar().setUI(new BasicScrollBarUI() );
pictureScrollPane.getHorizontalScrollBar().setUI(new BasicScrollBarUI());

to make it red. Or

pictureScrollPane.getVerticalScrollBar().setUI(new BasicScrollBarUI() {
            @Override 
            protected void configureScrollBarColors(){
                this.thumbColor = Color.BLUE;
            }
        });
        pictureScrollPane.getHorizontalScrollBar().setUI(new BasicScrollBarUI() {
            @Override 
            protected void configureScrollBarColors(){
                this.thumbColor = Color.BLUE;
            }
        });

to change scroll bars color.

  • This works great thanks! Now my UI Scrollpane can match the rest of my design! – Antonio Ferreras Oct 21 '18 at 19:44
  • You should not need to specifically reset the UI of the scrollbars. Just make sure you change the UIManager property BEFORE you create your Swing components. – camickr Oct 21 '18 at 20:51
  • @camickr For some strange reason, changing only UIManager properties has no effect what so ever. –  Oct 21 '18 at 20:59
  • Oops. I see your solution is actually changing the LAF of the scrollbar. so it would appear that the default LAF does not use the "Scrollbar.thumb" property. So instead of using the Metal LAF or the Window LAF or whatever, you are forcing it to be the Basic LAF. – camickr Oct 21 '18 at 21:54