Set scrollbar thickness

[亡魂溺海] 提交于 2019-12-12 09:34:15

问题


Is there a way to adjust the thickness of the scrollbar within a JScrollPane? the default is kind of clunky.


回答1:


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.




回答2:


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.




回答3:


int verticalScrollBarWidthCoefficient = 3;

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



回答4:


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



来源:https://stackoverflow.com/questions/5371547/set-scrollbar-thickness

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!