[英]How can I make vertical scroll bar invisible?
How do I make a vertical and or horizontal scroll bar invisible on a JScrollPane
in java. 如何在Java中的JScrollPane
上使垂直和/或水平滚动条不可见。
I've tried this, but doesn't work: 我已经尝试过了,但是没有用:
scrollPane.getVerticalScrollBar().setVisible(false);
Also, I would like to know how to make the bar visible again once it is not at a null state (I don't know the technical term) ie, see pic below. 另外,我想知道如何在不处于空状态时重新显示该条(我不知道技术术语),即,请参见下面的图片。 Bar is visible, but at a "null" state. 条是可见的,但处于“空”状态。
Also, is there a way to have the scroll bar remain invisible, but still allow for scrolling? 另外,有没有办法使滚动条保持不可见,但仍允许滚动?
The method you want is JScrollPane.setVerticalScrollBarPolicy() 您想要的方法是JScrollPane.setVerticalScrollBarPolicy()
Valid values are: 有效值为:
- ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED
- ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER
- ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS
I'm not entirely sure what you need, but it seems that you want to be using ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED
. 我不确定您需要什么,但似乎您想使用ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED
。
If those policies are not enough, you can write your wrapped view to implement the Scrollable interface, and you can change the policy inside the Scrollable.getScrollableTracksViewportHeight() method. 如果这些策略还不够,则可以编写包装视图以实现Scrollable接口,还可以在Scrollable.getScrollableTracksViewportHeight()方法内更改策略。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.