bytedeco / javacv

Java interface to OpenCV, FFmpeg, and more
Other
7.39k stars 1.56k forks source link

CanvasFrame setIconImage doesn't show running app icon #2240

Closed gareth-edwards closed 1 week ago

gareth-edwards commented 2 weeks ago

Forgive me in case it's really simple but this code that extends the Swing JFrame shows the running app icon in the Ubuntu dock:

public class Test extends JFrame {

    public Test(String title) {
        super(title);
    }

    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                Test frame = new Test("Test");
                frame.setIconImage(Toolkit.getDefaultToolkit().getImage(Test.class.getResource("logo.png")));
                frame.setVisible(true);
            }
        });
    } 
}

But this code that extends the Bytedeco CanvasFrame does not:

public class Test extends CanvasFrame {

    public Test(String title) {
        super(title);
    }

    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                Test frame = new Test("Test");
                frame.setIconImage(Toolkit.getDefaultToolkit().getImage(Test.class.getResource("logo.png")));
                frame.setVisible(true);
            }
        });
    }
}

Am I missing something really simple? How does one put an icon image on the CanvasFrame

Thanks and all the best,

saudet commented 2 weeks ago

BTW, you can keep using JFrame, CanvasFrame is just for convenience.

gareth-edwards commented 2 weeks ago

I love CanvasFrame! Used it to make a media player https://github.com/bytedeco/javacv/issues/2123

Just wish I knew how to get it to have an icon?

gareth-edwards commented 1 week ago

To get a custom icon when extending CanvasFrame, I have found that setIconImage has to be called before the setVisible in the CanvasFrame init method.

The easiest for me was:

public MyCanvasFrame(String title, double gamma) { super(title); setIconImage(Toolkit.getDefaultToolkit().getImage(MyCanvasFrame.class.getResource("logo.png"))); init(false, null, gamma); }