Changing thumb color and background color in JScrollPane?

I am having problems with the design of JScrollPane. I just want to change the color of both the large 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; } 

Besides

  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 the above code, I get a darkened thumb with a white background. Oddly enough, if I remove the setUI functions, I get a default finger with a darkened background.

Any ideas?

thanks


solvable ******


the above configureScrollBarColors function can be used as follows:

  @Override protected void configureScrollBarColors(){ this.thumbColor = Color.GREEN; } 

This changes the color of the thumb to green.

+6
source share
1 answer

Just in case, someone there still falls on this topic, seeking help:

The following line can be used to change the appearance of your scroll bar. Fields surrounded by "_" characters can be changed (key and COLOR).

 UIManager.put("ScrollBar._key_", new ColorUIResource(_COLOR_)); 

The most suitable keys for changing the color of your panel are:

  • thumb (General color of the thumb)
  • thumbDarkShadow (The remaining shadow of the thumb)
  • thumbShadow (Essentially a thumb border divided in half with backlight)
  • thumbHighlight (second half of the specified border type)
  • track (background)

So an example would be:

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

This will make the main part of the thumb black.

If you intend to use a full monochrome finger, use all keys except the track and set them to the same color.

If you are going to create a path, set the first two as color1 and the second as color2.

I fell for it, trying to improve my own GUI, and after some minor tweaking, I decided to share my findings.

For more keys, click me!

+1
source

All Articles