• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need ScrollPane with just VERTICAL Scrolling facility

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Please do not shoot the fish in this barrel. But you can shoot at this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic