Reputation: 2873
I'm having problems updating ( or refreshing) an Icon from button after closing a modal dialog. The image is basically overwritten by some actions of JDialog
.
This is my code:
conf = new Configurar(this, true,control);
conf.setVisible(true); // Open dialog
System.out.println("Cerrado"); // Check if is closed (debug)
String logo =(String)config.get("logo"); // get path from image
File newIcon =new File(logo); // Desesperate try
ImageIcon img = new ImageIcon(newIcon.getAbsolutePath());
btn_main_image.setIcon(img);
this.update(btn_main_image.getGraphics());
btn_main_image.updateUI(); // First Try
this.repaint(); // Second Try
The first time it works fine, but when I open the dialog and change the image remains the same.
Upvotes: 0
Views: 3853
Reputation: 347184
conf = new Configurar(this, true,control);
conf.setVisible(true); // Some kind of file chooser ??
File newIcon =new File(logo);
if (newIcon.exists()) {
ImageIcon img = new ImageIcon(newIcon.getAbsolutePath());
btn_main_image.setIcon(img);
//this.update(btn_main_image.getGraphics()); // WHAT IS THIS?!?!?!
//btn_main_image.updateUI(); // NO NO NO, this has nothing to do with refreshing the graphics, it's L&F stuff
btn_main_image.invalidate();
// Use this ONLY if invalidate doesn't work...
btn_main_image.revalidate();
btn_main_image.repaint();
}
Upvotes: 4