Reputation: 12192
Is there a way to adjust the thickness of the scrollbar within a JScrollPane
? the default is kind of clunky.
Upvotes: 18
Views: 19663
Reputation: 85
simplest way for me was to edit the jquery.jscrollpane.css
file directly. changing the width of .jspVerticalBar
. :)
Upvotes: -4
Reputation: 5505
The following applies to the default LNF (Metal).
If you just want to set a specific size, then you can put this code before you create the 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 you create the JScrollPane)...
UIManager.put("ScrollBar.width", (int) ((int) UIManager.get("ScrollBar.width") * 2.5));
If you want to change it after creating the JScrollPane things are a bit more complex, but not too bad...
int scrollbarSize = <some dynamic value>;
UIManager.put("ScrollBar.width", scrollbarSize);
scrollPane.setVerticalScrollBar(scrollPane.createVerticalScrollBar());
scrollPane.setHorizontalScrollBar(scrollPane.createHorizontalScrollBar());
I hope that helps someone.
Upvotes: 5
Reputation: 64632
int verticalScrollBarWidthCoefficient = 3;
scrollPane.getVerticalScrollBar().setPreferredSize(new Dimension(
(int) scrollPane.getVerticalScrollBar().getPreferredSize()
.getWidth() * verticalScrollBarWidthCoefficient,
(int) scrollPane.getVerticalScrollBar().getPreferredSize().getHeight()
));
Upvotes: 2
Reputation: 39197
A quick but also dirty solution is to set the width/height explicitely to e.g. 10 pixels via
jScrollPane.getVerticalScrollBar().setPreferredSize(new Dimension(10, 0));
jScrollPane.getHorizontalScrollBar().setPreferredSize(new Dimension(0, 10));
Other way would be to provide a proper ScrollBarUI
.
Upvotes: 27