My problem is quite simple: when I run the Java program below, nothing happens. The window does not ope. When I remove the lines between "begin of icon set" and "end of icon set" (setting the window icon), all works fine. I would like to add that the image file pointer obtained by ImageIO.read() is not null and does not cause any exception. In run it on a Linux system (LinuxMint 17.2) with Java Hotspot 1.8.0.
import java.awt.Image;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JLabel;
import elf.swing.View;
public class IconTest {
public static void main(String[] args) {
JFrame f = new JFrame("ok");
f.getContentPane().add(new JLabel("How are you?"));
// begin of icon set
Image im;
try {
im = ImageIO.read(View.class.getResourceAsStream("/pix/copy.png"));
if(im != null) {
java.util.List<java.awt.Image> imgs = new java.util.LinkedList<java.awt.Image>();
imgs.add(im.getScaledInstance(16, 16, 0));
f.setIconImages(imgs);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// end of icon set
f.pack();
f.setVisible(true);
}
}
So, I beg your help.