# How change icon to title bar

**URL:** <https://discourse.processing.org/t/how-change-icon-to-title-bar/37903>\
**Category:** Beginners\
**Created:** [July 10, 2022, 8:30am UTC](https://discourse.processing.org/t/how-change-icon-to-title-bar/37903 "2022-07-10T08:30:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andry](https://avatars.discourse-cdn.com/v4/letter/a/b487fb/32.png) [@Andry](https://discourse.processing.org/u/Andry)\
**Post date:** [July 10, 2022, 8:30am UTC](https://discourse.processing.org/t/how-change-icon-to-title-bar/37903/1 "2022-07-10T08:30:12Z")

</div>

_i tried with this code, but it gives me error_

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

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [July 10, 2022, 8:42am UTC](https://discourse.processing.org/t/how-change-icon-to-title-bar/37903/2 "2022-07-10T08:42:38Z")

</div>

This should work with Processing in Java Mode.

```auto
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

---

<div class="post-metadata">

**Author:** ![Andry](https://avatars.discourse-cdn.com/v4/letter/a/b487fb/32.png) [@Andry](https://discourse.processing.org/u/Andry)\
**Post date:** [July 10, 2022, 9:16am UTC](https://discourse.processing.org/t/how-change-icon-to-title-bar/37903/3 "2022-07-10T09:16:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![TimeLex](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/timelex/32/12869_2.png) [@TimeLex](https://discourse.processing.org/u/TimeLex)\
**Post date:** [July 10, 2022, 12:49pm UTC](https://discourse.processing.org/t/how-change-icon-to-title-bar/37903/4 "2022-07-10T12:49:37Z")

</div>

If you use `JAVA2D` you can simplify it by writing:

```auto
getSurface().setIcon(loadImage("icon.png"));

```

---

<div class="post-metadata">

**Author:** ![Andry](https://avatars.discourse-cdn.com/v4/letter/a/b487fb/32.png) [@Andry](https://discourse.processing.org/u/Andry)\
**Post date:** [July 10, 2022, 2:37pm UTC](https://discourse.processing.org/t/how-change-icon-to-title-bar/37903/5 "2022-07-10T14:37:29Z")

</div>

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”.
