java 设置滚动条粗细

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5371547/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 10:47:58  来源:igfitidea点击:

Set scrollbar thickness

javauser-interfacescrollbar

提问by Sinaesthetic

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

有没有办法在 a 内调整滚动条的粗细JScrollPane?默认设置有点笨重。

回答by Howard

A quick but also dirty solution is to set the width/height explicitely to e.g. 10 pixels via

一个快速但又脏的解决方案是通过明确地将宽度/高度设置为例如 10 像素

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

Other way would be to provide a proper ScrollBarUI.

另一种方法是提供适当的ScrollBarUI.

回答by xtempore

The following applies to the default LNF (Metal).

以下适用于默认的 LNF(金属)。

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)...

如果您只想设置特定大小,则可以在创建 JScrollPane 之前放置此代码(将 40 替换为您喜欢的任何大小)...

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)...

如果你想根据默认大小缩放滚动条,那么像这样(在你创建 JScrollPane 之前)......

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

If you want to change it aftercreating the JScrollPane things are a bit more complex, but not too bad...

如果您想创建 JScrollPane更改它事情会更复杂一些,但还不错......

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

I hope that helps someone.

我希望这可以帮助某人。

回答by Boris Pavlovi?

int verticalScrollBarWidthCoefficient = 3;

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

回答by user5890887

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

对我来说最简单的方法是jquery.jscrollpane.css直接编辑文件。改变 的宽度.jspVerticalBar。:)