I saw that this question has been asked many times, but I didn't find any solutions that works in my case.
I am trying to load an image and display it on a JDialog. That works when I am running the app from Eclipse, but when I generate the executable JAR (with Maven), and run the JAR, the JDialog appears without any image.
I put all my class in /src/main/java, and my image is in /src/main/resources. When I unpack the JAR generated by Maven, I can find my image, so I guess the problem isn't about Maven.
Here is the code I am using to load the image (I found it here : Eclipse exported Runnable JAR not showing images) :
URL url = myclass.class.getResource("/pic.gif");
ImageIcon icon = new ImageIcon(url);
If it can help, that's the entire code of the class :
public class LoadingWindow {
private JDialog dialog;
public LoadingWindow() {
this.dialog = new JDialog();
this.dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
this.dialog.setTitle("Veuillez patienter");
this.dialog.setSize(300, 200);
URL url = LoadingWindow.class.getResource("/wait.gif");
ImageIcon icon = new ImageIcon(url);
JLabel imageLabel = new JLabel();
imageLabel.setIcon(icon);
imageLabel.setHorizontalAlignment(JLabel.CENTER);
imageLabel.setVerticalAlignment(JLabel.CENTER);
this.dialog.getContentPane().add(imageLabel);
this.dialog.setLocationRelativeTo(null);
this.dialog.setVisible(true);
}
}
Thanks !