# Sending windows notifications within processing

**URL:** <https://discourse.processing.org/t/sending-windows-notifications-within-processing/39267>\
**Category:** Coding Questions\
**Created:** [October 14, 2022, 1:23pm UTC](https://discourse.processing.org/t/sending-windows-notifications-within-processing/39267 "2022-10-14T13:23:33Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shachar](https://avatars.discourse-cdn.com/v4/letter/s/bbce88/32.png) [@Shachar](https://discourse.processing.org/u/Shachar)\
**Post date:** [October 14, 2022, 1:23pm UTC](https://discourse.processing.org/t/sending-windows-notifications-within-processing/39267/1 "2022-10-14T13:23:33Z")

</div>

is it possible to send my own windows notifications using processing?  
I have tried to follow this [stack overflow question](https://stackoverflow.com/questions/34490218/how-to-make-a-windows-notification-in-java) but it doesn’t seem to be working in processing. I would really appreciate any help! Thanks in advance!

---

<div class="post-metadata">

**Author:** ![sableraph](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sableraph/32/251_2.png) [@sableraph](https://discourse.processing.org/u/sableraph)\
**Post date:** [October 14, 2022, 2:13pm UTC](https://discourse.processing.org/t/sending-windows-notifications-within-processing/39267/2 "2022-10-14T14:13:06Z")

</div>

Hi Shachar 🙂

Could you share your best attempt to port this example to Processing and the issues you are running into? This would make it easier for other community members to offer a solution.

---

<div class="post-metadata">

**Author:** ![Shachar](https://avatars.discourse-cdn.com/v4/letter/s/bbce88/32.png) [@Shachar](https://discourse.processing.org/u/Shachar)\
**Post date:** [October 14, 2022, 3:45pm UTC](https://discourse.processing.org/t/sending-windows-notifications-within-processing/39267/3 "2022-10-14T15:45:35Z")

</div>

Hi, I tried to copy the code, deleted “public” and “static” that didn’t work, but the code still can’t be run. now it looks like this:

```auto
import java.awt.*;
import java.awt.TrayIcon.MessageType;
class TrayIconDemo {
      void main(String[] args) throws AWTException {
        if (SystemTray.isSupported()) {
            TrayIconDemo td = new TrayIconDemo();
            td.displayTray();
        } else {
            System.err.println("System tray not supported!");
        }
    }
    public void displayTray() throws AWTException {
        //Obtain only one instance of the SystemTray object
        SystemTray tray = SystemTray.getSystemTray();
        //If the icon is a file
        Image image = Toolkit.getDefaultToolkit().createImage("icon.png");
        //Alternative (if the icon is on the classpath):
        //Image image = Toolkit.getDefaultToolkit().createImage(getClass().getResource("icon.png"));
        TrayIcon trayIcon = new TrayIcon(image, "Tray Demo");
        //Let the system resize the image if needed
        trayIcon.setImageAutoSize(true);
        //Set tooltip text for the tray icon
        trayIcon.setToolTip("System tray icon demo");
        tray.add(trayIcon);

        trayIcon.displayMessage("Hello, World", "notification demo", MessageType.INFO);
    }
}

```

---

<div class="post-metadata">

**Author:** ![PerryJohnson](https://avatars.discourse-cdn.com/v4/letter/p/57b2e6/32.png) [@PerryJohnson](https://discourse.processing.org/u/PerryJohnson)\
**Post date:** [October 14, 2022, 4:42pm UTC](https://discourse.processing.org/t/sending-windows-notifications-within-processing/39267/4 "2022-10-14T16:42:32Z")

</div>

UiBooster is a library that can do this.

> **[GitHub - Milchreis/UiBooster: 🚀 Creates fast and easy dialogs for utility tools](https://github.com/Milchreis/UiBooster/#system-tray)**
>
> 🚀 Creates fast and easy dialogs for utility tools. Contribute to Milchreis/UiBooster development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)\
**Post date:** [October 15, 2022, 3:54am UTC](https://discourse.processing.org/t/sending-windows-notifications-within-processing/39267/5 "2022-10-15T03:54:21Z")

</div>

The following code runs on my system (Mac). The ‘icon.png’ does not have to be in your sketch folder but you will need the complete url to load it (edit the one supplied below before running the code). Note that the demo uses Toolkit…getImage() instead of .createImage(). You should see the icon appear on the menuBar (right hand side on a Mac). When clicking on the icon, hold down the ‘control’ key at the same time and you should see a message dialog on the JOptionPane. Quit the sketch to close the icon.

```auto
import java.awt.*;
import java.awt.TrayIcon.MessageType;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JOptionPane;

void setup() {
  surface.setVisible(false);
  if (SystemTray.isSupported()) {
    println("supported.");
  } else {
    println("System tray not supported!");
  }
  SystemTray tray = SystemTray.getSystemTray();
  Image image = Toolkit.getDefaultToolkit().getImage("/Users/yourName/Desktop/images/icon.png");
  TrayIcon trayIcon = new TrayIcon(image, "Tray Demo");
  trayIcon.setImageAutoSize(true);
  trayIcon.setToolTip("Tray icon demo");
  trayIcon.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) { // Hold down control key while clicking on tray icon
      println("Icon clicked.");
      JOptionPane.showMessageDialog(null, "Some action performed.");
    }
  }
  );
  try {
    tray.add(trayIcon);
  }
  catch(AWTException e) {
    println(e);
  }
}

```

---

<div class="post-metadata">

**Author:** ![Shachar](https://avatars.discourse-cdn.com/v4/letter/s/bbce88/32.png) [@Shachar](https://discourse.processing.org/u/Shachar)\
**Post date:** [October 15, 2022, 2:30pm UTC](https://discourse.processing.org/t/sending-windows-notifications-within-processing/39267/6 "2022-10-15T14:30:23Z")

</div>

still not working …🙃

---

<div class="post-metadata">

**Author:** ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)\
**Post date:** [October 15, 2022, 4:08pm UTC](https://discourse.processing.org/t/sending-windows-notifications-within-processing/39267/7 "2022-10-15T16:08:05Z")

</div>

> still not working

Works fine on my system. Are you using Windows or MacOS? Any error messages? Usual reason for ‘not working’ is due to non-loading of the .png image. Path to image has to be well-defined; sticking the image in the sketch folder doesn’t work with this demo (unless you provide a complete path to the folder). It’s very difficult to tell what the problem is without seeing the exact code that you tried to run.

---

<div class="post-metadata">

**Author:** ![Shachar](https://avatars.discourse-cdn.com/v4/letter/s/bbce88/32.png) [@Shachar](https://discourse.processing.org/u/Shachar)\
**Post date:** [October 15, 2022, 4:12pm UTC](https://discourse.processing.org/t/sending-windows-notifications-within-processing/39267/8 "2022-10-15T16:12:42Z")

</div>

I’m using windows, and I checked that the file exists. the sketch is running but it doesn’t seem to be doing anything…

---

<div class="post-metadata">

**Author:** ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)\
**Post date:** [October 15, 2022, 4:27pm UTC](https://discourse.processing.org/t/sending-windows-notifications-within-processing/39267/9 "2022-10-15T16:27:08Z")

</div>

Do you see your icon image on the menuBar? On a Mac it won’t do anything unless you hold down the control key while you simultaneously click on the icon. At that point you should see the message dialog.

---

<div class="post-metadata">

**Author:** ![Shachar](https://avatars.discourse-cdn.com/v4/letter/s/bbce88/32.png) [@Shachar](https://discourse.processing.org/u/Shachar)\
**Post date:** [October 15, 2022, 4:34pm UTC](https://discourse.processing.org/t/sending-windows-notifications-within-processing/39267/10 "2022-10-15T16:34:47Z")

</div>

no, nothing happens 😢

---

<div class="post-metadata">

**Author:** ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)\
**Post date:** [October 15, 2022, 4:36pm UTC](https://discourse.processing.org/t/sending-windows-notifications-within-processing/39267/11 "2022-10-15T16:36:07Z")

</div>

Do you see the image?

---

<div class="post-metadata">

**Author:** ![Shachar](https://avatars.discourse-cdn.com/v4/letter/s/bbce88/32.png) [@Shachar](https://discourse.processing.org/u/Shachar)\
**Post date:** [October 15, 2022, 4:46pm UTC](https://discourse.processing.org/t/sending-windows-notifications-within-processing/39267/12 "2022-10-15T16:46:47Z")

</div>

i cannot see the image…

---

<div class="post-metadata">

**Author:** ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)\
**Post date:** [October 15, 2022, 4:57pm UTC](https://discourse.processing.org/t/sending-windows-notifications-within-processing/39267/13 "2022-10-15T16:57:51Z")

</div>

> i cannot see the image…

Most likely you haven’t loaded the image. I just tested it on an old 32-bit Windows PC with Processing 3.5.4 and it works on that system also. Make sure that the url looks something like this:

```auto
/Users/yourName/Desktop/images/icon.png

```

with the slash before Users. Also on Windows you have to double click while holding down the ‘ctrl’ key on your keyboard. There is another demo which uses a popUp menu which is easier to use, but I didn’t post it because it’s more complicated. The code that I posted is a Processing conversion of the original SO code that you copy/pasted.
