托盘图标在Ubuntu 16.04上不起作用 [英] Tray Icon not working on Ubuntu 16.04

查看:340
本文介绍了托盘图标在Ubuntu 16.04上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Ubuntu Gnome 16.04下遇到Java awt托盘图标的问题:

I ran into an Issue with Java awt tray icons under Ubuntu Gnome 16.04:

该图标显示在屏幕的左上角,并且在系统托盘中显示一个黑色正方形. MouseListener也不起作用(图标上或黑色方块上都没有).

The Icon is displayed in the top left corner of my screen and in the System Tray appears a black square. The MouseListener is also not working (neither on the icon nor on the black square).

这是我的代码:

if (SystemTray.isSupported()) {
   Image image = ImageIO.read(EyeUNIFYlocal.class.getResource("/star.png"));
   TrayIcon trayIcon = new TrayIcon(image);
   trayIcon.setImageAutoSize(true);

   trayIcon.addMouseListener(new MouseAdapter() {
      @Override
      public void mouseClicked(MouseEvent e) {
         System.out.println("Clicked");
      }
   });
   try {
      SystemTray.getSystemTray().add(trayIcon);
   } catch (AWTException ex) {
      System.err.println("Error while creating tray icon.");
   }
} else {
   System.err.println("Tray icons are not supported on this System.");
}

此代码在Windows 10上正常运行.

This code works fine on Windows 10.

提前谢谢!

推荐答案

较新的Linux发行版不存在Java系统托盘支持,这主要是由于从GtkStatusIcon到AppIndicator的更改以及GTK2/3的更改(因此,除非您安装一些其他库,否则JavaFX会出现问题.

Java System Tray support doesn't exist for newer Linux distributions, mostly because of the changes from GtkStatusIcon to AppIndicator, and GTK2/3 changes as well (so, issues with JavaFX unless you install some additional libraries).

此外,由于您提到了Gnome-Gnome喜欢将AppIndicator隐藏为通知",因此有一个扩展名(顶部图标),可让您将指示器恢复到屏幕顶部(而不是在屏幕左下方的隐藏抽屉中

Additionally, since you mentioned Gnome -- Gnome likes to "hide" the AppIndicator as "notifications", so there is an extension (top-icons) that lets you restore the indicators back to the top of the screen (instead of in a hidden drawer at the bottom left of the screen)

如果要显示跨平台系统任务栏图标,建议使用 SystemTray 项目.即将有一个入站3.0版本(API重写和更好的本机支持),但是较旧的2.x版本应该可以解决您遇到的问题.

If you want to display cross-platform system tray icons, I suggest the SystemTray project. There is an inbound 3.0 release soon (an API rewrite and better native support), but the older 2.x version should solve the problem you are having.

这篇关于托盘图标在Ubuntu 16.04上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆