Question

I tried to load a picture in my JDialog. So, I tried with JLabel like that:

ImageIcon icon = new ImageIcon("/sau/se/editor/images/HighBtomStPic.png");
System.out.println("Icon exists: "+(icon != null));
JLabel lblNewLabel = new JLabel();
lblNewLabel.setIcon(icon);

The print gives me true and I don't see the picture I have inserted, so what am I doing wrong?

Was it helpful?

Solution 2

Since I am dealing with source context not a file system one,

The answer should be: To replace:

ImageIcon icon = new ImageIcon("/sau/se/editor/images/HighBtomStPic.png");

With:

ImageIcon icon = new ImageIcon(GraphEditor.class.getResource("/sau/se/editor/images/HighBtomStPic‌​.png"));

OTHER TIPS

The constructor always returns an instance if it doesn't throw an exception. This is why the null check seems ok.

Instead, you should check to see that: icon.getImageLoadStatus() == MediaTracker.COMPLETE

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top