0

I have to write a little photo application for my studies and I have a problem: Basically I divided a frame into two sections: the upper section should display all of the images inside a folder in some kind of overview (thumbnails). If you select a thumbnail, the lower section of the frame should display the image in full size.

I'm not sure how to do the upper part right. I guess the best way to do it would be a JList with a horizontal LayoutOrientation?

I tried something like this:

public void loadIntoUpperSection(File directory){
   listmodel.removeAllElements();
   File[] images = directory.listFiles();
   for(int i=0; i<images.length; i++)
      listmodel.addElement(images[i]);
   }}

Now I should have all the paths to the images in my JList model, right? How would I display them? I read a lot of similar code but all of them include ImageIO and I'm not allowed to use it unfortunately (yeah...).

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
ramy
  • 64
  • 1
  • 15
  • *"all of them include ImageIO and I'm not allowed to use it"* Why not? See also the plethora of `createImage` methods in the [`Toolkit` methods](http://docs.oracle.com/javase/8/docs/api/java/awt/Toolkit.html#method.summary) as well as the `MediaTracker`. Or the [`ImageIcon` constructors](http://docs.oracle.com/javase/8/docs/api/javax/swing/ImageIcon.html#constructor.summary) or.. (there are a number of ways to load images that do not involve `ImageIO`). – Andrew Thompson Jan 09 '17 at 00:51
  • More generally to the question, yes, use a `JList`. The default renderer for a list is a `JLabel` which can accept an `ImageIcon`. While resizing a `BufferedImage` (as returned by `ImageIO`) is easy as it has inbuilt methods to do just that, you'll need to go through a few code lines to resize an `Image`. Probably best to encapsulate it in a method. – Andrew Thompson Jan 09 '17 at 00:54
  • 3
    [This answer](http://stackoverflow.com/a/11027533/418556) does almost what is required (the first example), except that the list is vertical and it uses `ImageIO`. See if you can adapt that to the requirement. – Andrew Thompson Jan 09 '17 at 01:02

0 Answers0