我在关闭模式对话框后更新(或刷新)来自按钮的图标时出现问题。该图像基本上被JDialog
的某些动作覆盖。如何从JButton/JLabel更新ImageIcon
这是我的代码:
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
第一次它工作正常,但是当我打开对话框并更改图像保持不变。
在部署时,'logo'图像可能不是文件系统上的'File',而是Jar内的资源。如果是这样,它必须由'URL'访问。 –