java 如何在 JScrollPane 中隐藏 JScrollBars

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5590242/
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 11:48:26  来源:igfitidea点击:

How to hide the JScrollBars in a JScrollPane

javaswing

提问by farm ostrich

I can't seem to find an answer to this on stackoverflow or at the javadoc site. It's probably very trivial. Could someone help?

我似乎无法在 stackoverflow 或 javadoc 站点上找到答案。这可能是非常微不足道的。有人可以帮忙吗?

回答by parth chandarana

I think with setHorizontalScrollBarpolicy() you can set scrollbar apperance means when you want to display your scrollbar like JScrollPane.VERTICAL_SCROLLBAR_ALWAYS displays vertical scrollbar always and so on.. This may help you.

我认为使用 setHorizo​​ntalScrollBarpolicy() 你可以设置滚动条外观意味着当你想显示你的滚动条时,比如 JScrollPane.VERTICAL_SCROLLBAR_​​ALWAYS 总是显示垂直滚动条等等..这可能对你有帮助。

        JScrollPane jsp = new JScrollPane(lista);
        jsp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
        jsp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);

回答by camickr

scrollpane.setHorizontalScrollBarPolicy(...) 
scrollpane.setVerticalScrollBarPolicy(...) 

回答by Enrico

Since you have added it I would assume you don't want it to show when the ContentPane size is still in range so the below code would make the ScrollBar to only show when the content of the ContentPane grows beyond the container size..

由于您已添加它,我假设您不希望它在 ContentPane 大小仍在范围内时显示,因此以下代码将使 ScrollBar 仅在 ContentPane 的内容超出容器大小时显示..

JScrollPane jsp = new JScrollPane(container, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEEDED);

For me I only prefer the vertical so if you're like me you should use the code below:

对我来说,我只喜欢垂直,所以如果你像我一样,你应该使用下面的代码:

JScrollPane jsp = new JScrollPane(container, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);