Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / November 2003

Tip: Looking for answers? Try searching our database.

Force JScrollPane to scroll in one direction only

Thread view: 
Rene Ruppert - 31 Oct 2003 15:04 GMT
Hi,

is there a way to force a JScrollPane to display a vertical scrollbar only
if the amount of components cannot be displayed within the visible area?

Background: I want to create a kind of thumb view where an unknown number of
thumbnails will be inserted. As long as there's space for another item it
will be displayed within the same line; if not it will be wrapped to the
next line. If the number of lines exceeds the available vertical space a
vertical scrollbar will be shown.
If the window is resized the thumbs are supposed to be wrapped according to
the current width.

I tried the following without succes:
- setHorizontalScrollBarPolicy() to never
- use FlowLayout Manager
- use GridLayout

I found lots of articles an Google - but all without a real solution.

Please help! :-(

cu

Rene
Thomas Fritsch - 31 Oct 2003 17:54 GMT
>is there a way to force a JScrollPane to display a vertical scrollbar only
>if the amount of components cannot be displayed within the visible area?

Call
   
yourScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);

Thomas
Thomas Fritsch - 31 Oct 2003 18:26 GMT
Thomas Fritsch schrieb:

>> is there a way to force a JScrollPane to display a vertical scrollbar
>> only
[quoted text clipped - 5 lines]
>
> Thomas

Sorry, I meant
   
yourScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);

Thomas
Babu Kalakrishnan - 01 Nov 2003 07:29 GMT
> Thomas Fritsch schrieb:
>
[quoted text clipped - 11 lines]
>    
> yourScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);

I think the first suggestion was the correct one. The
HorizontalScrollBarPolicy should be set to NEVER.

Some more points to remember are - a) Use an appropriate LayoutManager
for the panel that is inside the viewport, b) *Not* calling
setPreferredSize on this panel, c) Having the panel implement the
Scrollable interface and return "true" for the
getScrollableTracksViewportWidth method and "false" for
getScrollableTracksViewportHeight method.

Read the documentation of javax.swing.Scrollable and JScrollPane, as
well as the Java Tutorial chapter on How to use JScrollPane.

BK
Rene Ruppert - 03 Nov 2003 09:10 GMT
Hi Thomas,

yourScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_
NEEDED);

yourScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR
_AS_NEEDED);

sorry, but both won't work. Setting the scrollbar policies has no effect.
Setting horizontal to NEVER disables the scrolling completely without
leading to a wrapping of the content and setting vertical to AS_NEEDED won't
show a bar at all.

Anyway thanks.

cu

Rene
Babu Kalakrishnan - 04 Nov 2003 11:22 GMT
> yourScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_
> NEEDED);
[quoted text clipped - 8 lines]
>
> Anyway thanks.

Did you try implementing the Scrollable interface ? If not, try doing that.

Are you by any chance setting some hardcoded values to the preferredSize
parameter of the panel ? If you did so, remove that piece of code.

Difficult to guess further without seeing some code. I'm sure a lot of
people have used a JScrollPane in a zillion applications without having
a similar problem - which means you must be doing something wrong in
your code.

BK


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.