I want to display an image on a application and when I want to open another one, I want that the new one overwrite the old.
I've looking everywhere to find a solution like use invalidate(), repaint(), etc.. but still not working and I can't figured out why the windows doesn't refresh, can someone help me?
Here the code :
public void actionPerformed(ActionEvent e)
{
System.out.println(e.getActionCommand());
if (e.getActionCommand().contains("Open"))
{
filename_ = new String();
filename_ = JOptionPane.showInputDialog("File to open ?");
ImagePanel test = new ImagePanel(new File(filename_));
test.setPreferredSize(new Dimension(test.getWidth(), test.getHeight()));
test.setMinimumSize(new Dimension(test.getWidth(), test.getHeight()));
test.repaint();
JScrollPane tmp = new JScrollPane();
tmp.getViewport().add(test);
tmp.getViewport().repaint();
mainPanel_.add(tmp, BorderLayout.NORTH);
mainPanel_.repaint();
curim_ = test;
test.memento_ = new Memento(test);
test.caretaker_.add(test.memento_);
curim_ = test;
curmodindex_ = curim_.caretaker_.getIndex();
this.setContentPane(mainPanel_);
System.out.println(curmodindex_);
if (curmodindex_ != 0)
{
button1.setEnabled(true);
button2.setEnabled(true);
}
}