aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Show a JList In A scroll Pane Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Show a JList In A scroll Pane" Watch "Show a JList In A scroll Pane" New topic
Author

Show a JList In A scroll Pane

Stanley Mungai
Ranch Hand

Joined: Dec 09, 2011
Posts: 155

Hi friends I am trying to Get A Jlist Into a scrollpane But I do not seem to succees because I do not see the ScrollPane:



What am I doing wrong?


Give a beggar a fish; feed him for a day. Teach him how to fish; Feed him for a lifetime.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38412
    
  23
What do you mean by don’t see the scroll pane? Do you see the List? Is the List larger or smaller than the scroll pane was expected to be? What happens if you resize your frame smaller?
Stanley Mungai
Ranch Hand

Joined: Dec 09, 2011
Posts: 155

Yes RItchie I see the List But I do not See the Scroll Pane and If the List is very Long it Disappers into the JPanel.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10268
    
    8

You have set the layout for the jpAcc to null.
Change it to BorderLayout


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Stanley Mungai
Ranch Hand

Joined: Dec 09, 2011
Posts: 155

It looks the same ..The List is there without the ScrollPane
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10268
    
    8

You are adding the list twice. You don't need jpAcc.add(checkBoxesJList);
Stanley Mungai
Ranch Hand

Joined: Dec 09, 2011
Posts: 155

The List Is still there without the Scroll Pane
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10268
    
    8

Shrink the frame height to see it
Stanley Mungai
Ranch Hand

Joined: Dec 09, 2011
Posts: 155

Oh Nice I can see it Now But have Other components on The Jpanel. I will Habe to Shrink Them too?
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10268
    
    8

No. You have to drop the null layout/bounds and start using proper layout managers. More about them here http://docs.oracle.com/javase/tutorial/uiswing/layout/visual.html

The scroll will show up, when the available visual space is less than the required display space.
m Korbel
Ranch Hand

Joined: Jun 19, 2012
Posts: 155
crossposted and answered
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38412
    
  23
And he got a nice answer on SO. Please read this.
 
Consider Paul's rocket mass heater.
 
subject: Show a JList In A scroll Pane