How to display next image selected by file chooser next time This is my code that had a filechooser to choose file and display the image on jlabel. The image is scaled to proper size correctly but when i try to choose next or other image file through filechooser..the new image did not displayed out..previous image stills there..not able to display the updated image.. I have also set the path name of image in the textfield and it gets set correctly.but the image is not updated on jlabel...
please any one tell me where is
my code wrong..
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
JFileChooser jFileChooser1 = new JFileChooser();
repaint();
jFileChooser1.setAcceptAllFileFilterUsed(false);
int state = jFileChooser1.showOpenDialog(new JFrame());
jTextField1.setText("");
jLabel1 = new JLabel();
if (state == JFileChooser.APPROVE_OPTION) {
file = jFileChooser1.getSelectedFile();
s2 = file.toString();
jTextField1.setText(s2);
jLabel1.setName(s2);
jLabel1.setLocation(40, 40);
jLabel1.setSize(300, 300);
jLabel1.setVisible(true);
try {
bi = ImageIO.read(file);
// JOptionPane.showMessageDialog(new JFrame(),file.getName());
icon = new ImageIcon(bi);
Image img = icon.getImage();
icon = new ImageIcon(file.getPath());
// icon = new ImageIcon(paths[currentIndex].getPath());
scaleImage = icon.getImage().getScaledInstance(80, 80,
Image.SCALE_DEFAULT);
resizedImage = resize(bi, 200, 200);
icon = new ImageIcon(resizedImage);
jLabel1.setIcon(icon);
jLabel2 = new JLabel();
repaint();
pack();
paths = file.getParentFile().listFiles();
currentIndex = indexOf(paths, file);
} catch (Exception e) {
System.out.println(e);
}
} else if (state == JFileChooser.CANCEL_OPTION) {
JOptionPane.showMessageDialog(new JFrame(), "Canceled");
}
add(jLabel1);
}