Set the thickness of the scroll bar

Is there a way to adjust the thickness of the scrollbar within a JScrollPane ? by default it is inconvenient.

+7
source share
4 answers

A quick but also dirty solution is to set the width / height explicitly, for example. 10 pixels across

 jScrollPane.getVerticalScrollBar().setPreferredSize(new Dimension(10, 0)); jScrollPane.getHorizontalScrollBar().setPreferredSize(new Dimension(0, 10)); 

Another way would be to provide the correct ScrollBarUI .

+16
source
 int verticalScrollBarWidthCoefficient = 3; scrollPane.getVerticalScrollBar().setPreferredSize(new Dimension( (int) scrollPane.getVerticalScrollBar().getPreferredSize() .getWidth() * verticalScrollBarWidthCoefficient, (int) scrollPane.getVerticalScrollBar().getPreferredSize().getHeight() )); 
+2
source

The following relates to the LNF standard (metal).

If you just want to set a specific size, you can put this code before creating a JScrollPane (replace 40 with whatever size you prefer) ...

 UIManager.put("ScrollBar.width", 40); 

If you want to scale the scrollbar based on the default size, then something like this (before creating JScrollPane) ...

 UIManager.put("ScrollBar.width", (int) ((int) UIManager.get("ScrollBar.width") * 2.5)); 

If you want to change it after creating JScrollPane, it will be a little more complicated, but not so bad ...

 int scrollbarSize = <some dynamic value>; UIManager.put("ScrollBar.width", scrollbarSize); scrollPane.setVerticalScrollBar(scrollPane.createVerticalScrollBar()); scrollPane.setHorizontalScrollBar(scrollPane.createHorizontalScrollBar()); 

I hope this helps someone.

+2
source

The easiest way for me was to directly edit the jquery.jscrollpane.css file. changing the width of the .jspVerticalBar . :)

-one
source

All Articles