开发者

Set scrollbar thickness

Is there a way to adjust the thickness of the开发者_C百科 scrollbar within a JScrollPane? the default is kind of clunky.


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.


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.


int verticalScrollBarWidthCoefficient = 3;

scrollPane.getVerticalScrollBar().setPreferredSize(new Dimension(
        (int) scrollPane.getVerticalScrollBar().getPreferredSize()
                .getWidth() * verticalScrollBarWidthCoefficient,
        (int) scrollPane.getVerticalScrollBar().getPreferredSize().getHeight()
));


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜