farm ostrich
farm ostrich

Reputation: 5949

How to hide the JScrollBars in a JScrollPane

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?

Upvotes: 5

Views: 14513

Answers (3)

Enrico
Enrico

Reputation: 131

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..

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

Upvotes: 0

parth chandarana
parth chandarana

Reputation: 262

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.

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

Upvotes: 14

camickr
camickr

Reputation: 324098

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

Upvotes: 4

Related Questions