views:

184

answers:

4

Here is my problem:

I have an application that every iteration it returns to me a list of images. The imagens have different sizes and the number of images to be shown varies every time.

Is there a way to show in a jFrame all the images without knowing the number of jPanels to create? Is there an easy way to do that?

Obs.: The images should be shown at same time, like side by side, or listed, because they are used for comparisson purposes.

Obs.2: The number of images to be shown is around 20-60 for each time.

Thanks

+3  A: 

this solution should work:

class MyFrame extends JFrame
{
MyFrame(Image images[])
 {
 JTabbedPane tabbed= new JTabbedPane();
 setContentPane(tabbed);
 for(int i=0;i< images.length;++i)
  {
  tabbed.addTab("Image "+i, new JScrollPane(new JLabel(new ImageIcon(images[i]))));
  }
 }
Pierre
Actually this makes a lot more sense than my answer, so +1
Erkan Haspulat
@Pierre, I didn't say that in my question, but the user should be able to see all the images at same time. I'm not shure this can be done with a JTabbedPane. Thanks
marionmaiden
+1  A: 

From your question I assume that you are able to show images in a JPanel. In that case, you can keep a list of JPanels and dynamically update this list. Of course, the layout to be drawn on the JFrame is completely up to you, but for a job like this one, you might want to use GridLayout or BoxLayout.

To keep a list of JPanels:

ArrayList<JPanel> panelList = new ArrayList<JPanel>();
...
panelList.add(new JPanel());
...
panelList.clear;
Erkan Haspulat
@Erkan, your solution worked fine for me. Thanks
marionmaiden
+4  A: 

As you want to see all your images in the same Panel, I suggest you use a TreeMap Algorithm to display your panels using the dimension of your image as the weight of each image. And then, resize each image so it can fit in each panel.

alt text

See a Java implementation here: http://plindenbaum.blogspot.com/2009/08/treemap-for-friendfeed.html

Pierre
+2  A: 

If you use JInternalFrame for this, you can drag the pictures around and change the size, too.

Catalina Island