1

could any one suggest me the way to show multiple images in tab of jtabbedpane for example i would like to show thumbnail view of images and on selecting the image it should open in a other tab?

i have put part my code to show what i want. here i had drawn the image but i actually want to load those image to allow them to select for editing.

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;
        }
   }
} 
mKorbel
  • 109,525
  • 20
  • 134
  • 319
Jony
  • 1,035
  • 7
  • 17
  • 43

1 Answers1

2
  1. Use JPanel with GridLayout or GridBagLayout to display a list of JLabels.
  2. Set one image for each label and attach a MouseListener to each label. On click of the label create a new JPanel or JLabel with a large image and add it to tab
Pragalathan M
  • 1,673
  • 1
  • 14
  • 19