ti dico la verità che tutto quel codice non l'ho nemmeno provato
...
Questo va però... vedi se magari riesci a tirarne fuori qualcosa di utile anche per la tua applicazione.
codice:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class displayImages extends JFrame implements ActionListener {
File f;
JLabel img;
JScrollPane sc;
private ImageIcon createImageIcon(String path) {
try {
return new ImageIcon(path);
}
catch (Exception e) {
System.out.println(e.toString());
return null;
}
}
public void actionPerformed (ActionEvent ae) {
try {
JFileChooser fc = new JFileChooser();
fc.showDialog(this, "Choose Image");
f = fc.getSelectedFile();
try {
img.setVisible(false);
sc.setVisible(false);
}
catch (Exception ex) {}
img = new JLabel(createImageIcon(f.getAbsolutePath()));
sc = new JScrollPane(img);
this.getContentPane().add(sc, BorderLayout.CENTER);
this.validate();
}
catch (Exception e) {}
}
public displayImages() {
super("Image display");
JButton open = new JButton("Open...");
this.getContentPane().setLayout(new BorderLayout());
this.getContentPane().add(open, BorderLayout.NORTH);
open.addActionListener(this);
this.setSize(300, 300);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main (String[] args) {
displayImages d = new displayImages();
}
}