Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The system tray is not supported on the current platform?

I'm trying to make a System Tray application on Ubuntu 18.04 using Java.

This is the code that I'm executing:

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class App {
    static{
        System.setProperty("java.awt.headless", "false");
    }
    public static void main(String[] args) {

//       if(!SystemTray.isSupported()){
//           System.out.println("System Tray is not supported.");
//           return;
//       }
       final PopupMenu popup = new PopupMenu();
       Image img = Toolkit.getDefaultToolkit().createImage("/path/img.png");
       final TrayIcon trayIcon = new TrayIcon(img);
       final SystemTray systemTray = SystemTray.getSystemTray();

       //create components of system tray
        trayIcon.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent actionEvent) {
                System.out.println("In here!");
                trayIcon.displayMessage("Test","Some action happened",TrayIcon.MessageType.INFO);
            }
        });

        try{
            systemTray.add(trayIcon);
        }catch(AWTException e){
            System.out.println("TrayIcon could not be added.");
        }

    }


}

I commented out the isSupported() method test snippet because I kept getting "System tray is not supported".

The Exception I'm getting is:

Exception in thread "main" java.lang.UnsupportedOperationException: The system tray is not supported on the current platform. at java.awt.SystemTray.getSystemTray(SystemTray.java:186) at App.main(App.java:16)

Any idea how I would make it supported? Also, if anyone has a MacOS device, can you try it, and let me know if it works? Thanks!

like image 938
user3676224 Avatar asked May 20 '18 23:05

user3676224


1 Answers

Gnome 3.28 (used in Ubuntu 18.04) removed the System tray. There is a software called TopIcon Plus Gnome Shell Exetension which returns the System tray. I tested the code, and the effects were as expected. An icon was placed in the Global bar.

https://extensions.gnome.org/extension/1031/topicons/

like image 88
user3676224 Avatar answered Sep 29 '22 14:09

user3676224