How To Generate or Show thumbnail view of images in a tab of JTabbedPane in java and allow user to click on that image to be display in other tab of a JTabbedpane ?
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;
}
}
}
well this what i am trying here instated of drawing image i want to actully load and show the image so dat i can click on image and open it in another tab to edit the image i some how able to know that it can be done by using jlist but how that i dont know. please suggest me the way
Here are some hints to help you:
To display image in other tab:
For more help show us what you have tried and better if you can post a short working code example which demonstrate your problem.
EDIT
For another requirement described in comment:
This is just demo code, you might need to modify it based on your requirements. This is just to show you how you can monitor click on 2 components and get them in another tab.
Wish you have asked a different question for this I might have got some upvotes/accepted answer or the best some bounty or the worst down votes.