tags:

views:

167

answers:

1

Ok, I am trying to add one row of multiple images to a JPanel, it can range from 15 - 30 images so I need to have a horizontal Scroll Pane in the JPanel.

Now comes the hard part, how can I make it so the images can be removed then a new amount of images can be in its place?

+1  A: 

You can either:

a) remove the images individually from the panel using the remove() method and then revalidate() the panel

or

b) create a new panel with the new images and then add the panel to the scrollpane using the setViewportView(...) method.

camickr
Another question, how do I make it to where it cant display 1/2 an image? And thank you very much!
Cody
+1 @Cody: if the widths are homogeneous, `getViewport().setPreferredSize()` to a multiple of the width; http://java.sun.com/docs/books/tutorial/uiswing/components/scrollpane.html
trashgod