Jony
Jony

Reputation: 1025

Image thumbnail view/editor in JFrame

Could anyone suggest to me how to load multiple images in one tab and after clicking on a particular image it should open in another tab for image processing?

here is the part of my code. here instead if drawing image i actually required to open the load the the images and on selecting particular image it should open to other tab. please suggest me how is it done using jlist or by any other means..

import javax.swing.*;
import java.awt.*;
import java.awt.Event.*;
import java.io.File;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import java.io.IOException;

public class SwindDesign {
public static void main(String[] args) throws IOException {
    JFrame frame = new JFrame("Split Pain");
    frame.setSize(700, 500);
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLayout(new GridLayout());

    //panel
    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
    panel.add(new PicturePanel());

   JTabbedPane jtp = new JTabbedPane();

     jtp.addTab("Set Image", panel);
      jtp.addTab("Compare Image", new JButton());
      frame.add(jtp);

    }
}
class PicturePanel extends JPanel {

File folder = new File("C:/Documents and Settings/All Users/Documents/My Pictures/Sample Pictures");
File[] listOfFiles = folder.listFiles();
ImageIcon[] img ;
JComponent lblimg;
JTabbedPane jtp = new JTabbedPane();
private BufferedImage[] b = new BufferedImage[10];

public PicturePanel() throws IOException {
    for (int i = 0; i < listOfFiles.length; i++) {
        System.out.println("chek panth"+listOfFiles[i].getName().toString());
        b[i] = ImageIO.read(new File("C:/Documents and Settings/All Users/Documents/My Pictures/Sample Pictures/" + listOfFiles[i].getName().toString()));
    }
}

@Override
protected void paintComponent(Graphics g) {
    super.paintComponents(g);
    Graphics2D g2 = (Graphics2D) g;
    int k = 10;
    for (int j = 0; j < listOfFiles.length - 1; j++) {
        g2.drawImage(b[j], k, 0, 100, 100, null);
        k = k + 75;
        }
    }
}

Upvotes: 1

Views: 1533

Answers (1)

Andrew Thompson
Andrew Thompson

Reputation: 168815

could anyone suggest me how to load multiple..

Use a loop.

..images..

Use ImageIO.read(File/URL/InputStream)

in on tab..

Add a JPanel to the tab with a suitable layout, E.G. FlowLayout or GridLayout. Put the image in an undecorated JButton and add it to the panel.

..and after clicking on a particular image..

Add an ActionListener to the button.

..it should open inn a other tab for image processing.

JTabbedPane.addTab("image name", imageEditorComponent)

Upvotes: 4

Related Questions