简体   繁体   中英

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.

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

Valid values are:

  • ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED
  • ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER
  • 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 .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM