0

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.

  • How long takes the execution of `im.getScaledInstance(16, 16, 0)` , and how big is your original image ? – Arnaud Dec 09 '16 at 13:35
  • `im.getScaledInstance(16, 16, 0)` Windows at least, will scale the image to fit whatever size it typically uses (based on user preferences of theme etc.). See also [Sizes of frame icons used in Swing](http://stackoverflow.com/q/18224184/418556). – Andrew Thompson Dec 09 '16 at 13:55
  • It takes a very short time (at least stated from the debugger). – Cassé Hugues Dec 09 '16 at 14:12
  • You're right with getScaledInstance(). From the debugger, getSCaledInstance() takes a very short time (debugger does not block on it) but the window is not opened. But if I remove it, all works fine. Is the scaling done asynchronously? – Cassé Hugues Dec 09 '16 at 14:17

0 Answers0