• Post Reply Bookmark Topic Watch Topic
  • New Topic

Need ScrollPane with just VERTICAL Scrolling facility  RSS feed

 
Florin Constantinescu
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my application I have a JSplitPane. In the right pane of it I have a JPanel; in the panel I have a JList with list.setLayoutOrientation(JList.HORIZONTAL_WRAP).
I want to place the panel in a JScrollPane, but I DONT want the horizontal scrolling facility(for obvious reasons - the HORIZONTAL_WRAP wouldn't work as it should in case of moving the split pane's divider to the right because of the existing horizontal scrollbar).
Of course, the vertical scrolling function is a must, so that the list can actually wrap.

How can I obtain a JScrollPane with just vertical scrolling facility?

It's not the "scroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);", because this only hides it; doesn't disable it.
And "scroll.getHorizontalScrollBar().setEnabled(false);" doesn't get results either, because this disables only the knob.
What I need is just a vertical ScrollPane. How do I get it?
 
Rob Camick
Ranch Hand
Posts: 2801
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It works fine when the scrollpane is just added to a panel. I don't know why it would be any different when added to a split pane.

If you need further help then you need to create a SSCCE (Short, Self Contained, Compilable and Executable, Example Program), that demonstrates the incorrect behaviour.

Don't forget to use the Code Formatting Tags so the posted code retains its original formatting. That is done by selecting the code and then clicking on the "Code" button above the question input area.
 
Florin Constantinescu
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your answer.
I've solved it. The problem was the JPanel. I put the JList directly in the JScrollPane, and then I have added the scroll into the panel. Now the panel(not the scroll) is nested by the JSplitPane. And it works like a charm. The main idea is that the JList must be placed directly in the JScrollPane, for the lather to take notice of JList's method "boolean getScrollableTracksViewportWidth()"(Scrollable interface), which returns true in the case of horizontal wrapping. JPanel doesn't implement Scrollable, unfortunately.
For specific details, this is a proper source: Scrollable tips.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!