【问题标题】:The system tray is not supported on the current platform?当前平台不支持系统托盘?
【发布时间】:2018-05-20 23:25:26
【问题描述】:

我正在尝试使用 Java 在 Ubuntu 18.04 上制作系统托盘应用程序。

这是我正在执行的代码:

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.");
        }

    }


}

我注释掉了 isSupported() 方法 test sn-p,因为我一直收到“不支持系统托盘”。

我得到的例外是:

线程“main”中的异常 java.lang.UnsupportedOperationException:当前平台不支持系统托盘。 在 java.awt.SystemTray.getSystemTray(SystemTray.java:186) 在 App.main(App.java:16)

知道如何支持它吗? 另外,如果有人有 MacOS 设备,你可以试试,让我知道它是否有效?谢谢!

【问题讨论】:

  • 它适用于 MacOS 设备。

标签: java ubuntu system-tray trayicon ubuntu-18.04


【解决方案1】:

Gnome 3.28(在 Ubuntu 18.04 中使用)移除了系统托盘。 有一个名为TopIcon Plus Gnome Shell Exetension 的软件,它返回系统托盘。 我测试了代码,效果符合预期。全局栏中放置了一个图标。

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

【讨论】:

  • 据报道它在某些 Gnome 40 版本中不起作用。有更新吗?
  • 是否有关于如何使用扩展的教程或指南?
猜你喜欢
  • 2013-08-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-09-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多