I am having trouble styling a JScrollPane. I just want to be able to change the color of both the thumb and the background (and also remove the increase/decrease buttons). So far I have tried the following:
this.setBackground(new Color(0,0,0));
this.viewport.setBackground(new Color(0,0,0));
this.getViewport().setBackground(Color.BLACK);
this.setOpaque(false);
this.getVerticalScrollBar().setUI(new BasicScrollBarUI()
{
@Override
protected JButton createDecreaseButton(int orientation) {
return createZeroButton();
}
@Override
protected JButton createIncreaseButton(int orientation) {
return createZeroButton();
}
@Override
protected void configureScrollBarColors(){
}
});
this.getHorizontalScrollBar().setUI(new BasicScrollBarUI()
{
@Override
protected JButton createDecreaseButton(int orientation) {
return createZeroButton();
}
@Override
protected JButton createIncreaseButton(int orientation) {
return createZeroButton();
}
});
}
private JButton createZeroButton() {
JButton jbutton = new JButton();
jbutton.setPreferredSize(new Dimension(0, 0));
jbutton.setMinimumSize(new Dimension(0, 0));
jbutton.setMaximumSize(new Dimension(0, 0));
return jbutton;
}
Also
UIManager.put("ScrollBar.trackHighlightForeground", (new Color(57,57,57)));
UIManager.put("scrollbar", (new Color(57,57,57)));
UIManager.put("ScrollBar.thumb", new ColorUIResource(new Color(57,57,57)));
UIManager.put("ScrollBar.thumbHeight", 2);
UIManager.put("ScrollBar.background", (new Color(57,57,57)));
UIManager.put("ScrollBar.thumbDarkShadow", new ColorUIResource(new Color(57,57,57)));
UIManager.put("ScrollBar.thumbShadow", new ColorUIResource(new Color(57,57,57)));
UIManager.put("ScrollBar.thumbHighlight", new ColorUIResource(new Color(57,57,57)));
UIManager.put("ScrollBar.trackForeground", new ColorUIResource(new Color(57,57,57)));
UIManager.put("ScrollBar.trackHighlight", new ColorUIResource(new Color(57,57,57)));
UIManager.put("ScrollBar.foreground", new ColorUIResource(new Color(57,57,57)));
UIManager.put("ScrollBar.shadow", new ColorUIResource(new Color(57,57,57)));
UIManager.put("ScrollBar.highlight", new ColorUIResource(new Color(57,57,57)));
With all of the above code I get a darkened thumb with a white background. Funnily enough if I remove the setUI functions, I get a default thumb with a darkened background..
Any ideas?
Thanks
SOLVED******
the configureScrollBarColors function above can be used in the following way:
@Override
protected void configureScrollBarColors(){
this.thumbColor = Color.GREEN;
}
That changes the color of the thumb to green.