How change icon to title bar

i tried with this code, but it gives me error

ImageIcon icon = new ImageIcon(“icona.ico”);
import javax.swing.*;
JFrame jf;
jf.setIconImage(icon);

This should work with Processing in Java Mode.

JFrame frame = (JFrame) ((processing.awt.PSurfaceAWT.SmoothCanvas) window.getSurface().getNative()).getFrame();
frame.setIconImage((java.awt.Image) loadImage("icon.png").getNative());  

Note: This will not work in P2D and P3D because GLWindow class does not support changing the icon

1 Like

Thanks, as you wrote in Processing it doesn’t work, too bad.

If you use JAVA2D you can simplify it by writing:

getSurface().setIcon(loadImage("icon.png"));
4 Likes

Thanks, then I realized that the problem was the icon file, I just replaced the “.ico” file with a “.png” file and it worked. The light bulb went on seeing your codes that used a “.png”.

1 Like