File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes JScrollpane problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JScrollpane problem" Watch "JScrollpane problem" New topic

JScrollpane problem

Maarten Vergouwen
Ranch Hand

Joined: Jan 12, 2004
Posts: 60
I'm having trouble getting a JScrollpane to do what it is supposed to do, ie enable scrolling.

What I want to do is add scrolling to a JList. I have coded the following:

jScrollPane1 = new javax.swing.JScrollPane();

Then I add items to the list using:

When I then add items to the list, I see them added just fine, but once the entire list is filled on screen, no scrollbar appears though items continue to be added.

Can anyone tell me what could be wrong?

Rachel Swailes
Ranch Hand

Joined: May 18, 2004
Posts: 434
Hi there,

Why not try an easier approach to getting your JList to scroll.

JScrollPane myScrollPane = new JScrollPane(myList, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);

That's all you need.

Give me a shout if you need more help,
Maarten Vergouwen
Ranch Hand

Joined: Jan 12, 2004
Posts: 60
Thank you for your help Rachel.
After seeing your bit of code work fine, my error turned out to be far more elementary than I'd feared (unreachable code because of a careless comment.... highly embarrasing ).

I agree. Here's the link:
subject: JScrollpane problem
It's not a secret anymore!