开发者

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 tr开发者_JAVA技巧ivial. Could someone help?


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


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


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜