[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

To display a list of images in different pages

Posted on 2005-04-19
5
Medium Priority
?
210 Views
Last Modified: 2010-07-27
Hi,

I have this code snippet which enable me to display my 10 images in one page, each having a scrollbar to move around each image.

public void displayImages(){
     File f[] = new File(".").listFiles();
     for (int i=0; i<f.length; i++) {
       if (f[i].getName().endsWith(".tiff")) {
         try {
           FileSeekableStream stream = new FileSeekableStream(f[i]);
           ParameterBlock params = new ParameterBlock();
           params.add(stream);
           TIFFDecodeParam decodeParam = new TIFFDecodeParam();
           decodeParam.setDecodePaletteAsShorts(true);
           RenderedOp tiffImage = JAI.create("TIFF", params);
           ScrollingImagePanel panel = new ScrollingImagePanel(tiffImage,tiffImage.getWidth(),
                                       tiffImage.getHeight());
           getContentPane().add(panel);
         }
         catch (Exception e) {
           System.out.println("Images not displayed");
         }
       }
     }
   }

Now I want to change it so that I can view each of my images with their actual sizes in different pages. Anyone can help me out here? Thanks in advance.
0
Comment
Question by:hzinox
  • 3
5 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 13814584
Create a JTabbedPane with f.length tabs, then call that code for each tab
0
 

Author Comment

by:hzinox
ID: 13814627
Hi CEHJ,

Can you please explain a bit on how I can do that. I know I must now look for information on JTabbedPane layout but if you could show me here then it sure help me out. I am doing my developing as well as exploring and learning Java in parallel, so it is quite a lot to do at one time :-).



0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 1000 total points
ID: 13814646
Tabbed panes are pretty straightforward:

http://java.sun.com/docs/books/tutorial/uiswing/components/tabbedpane.html

All you need to do is call that code above once for each tab
0
 
LVL 2

Accepted Solution

by:
limaideal earned 1000 total points
ID: 13816571
It will look something like:

JTabbedPane tabPane = new JTabbedPane(); <<=====
getContentPane().add(tabPane);
File f[] = new File(".").listFiles();
     for (int i=0; i<f.length; i++) {
       if (f[i].getName().endsWith(".tiff")) {
         try {
           FileSeekableStream stream = new FileSeekableStream(f[i]);
           ParameterBlock params = new ParameterBlock();
           params.add(stream);
           TIFFDecodeParam decodeParam = new TIFFDecodeParam();
           decodeParam.setDecodePaletteAsShorts(true);
           RenderedOp tiffImage = JAI.create("TIFF", params);
           ScrollingImagePanel panel = new ScrollingImagePanel(tiffImage,tiffImage.getWidth(),
                                       tiffImage.getHeight());
           tabPane.add(f[i].getName(), panel); <<=====
         }
         catch (Exception e) {
           System.out.println("Images not displayed");
         }
       }
     }
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 14179095
:-)
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month18 days, 12 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question