java的SystemTray不适用于Gnome 3.14

时间:2015-10-19 14:25:10

标签: java awt gnome-3

我试图在gnome的通知面板上放置一个Java SystemTray图标(我使用的是使用gnome 3.14的OpenSuse 13.2)。

虽然SystemTray.isSupported()正在返回" true"但它无法正常工作。我在屏幕上看不到任何图标。我希望它出现在OpenSuse的通知区旁边。

这是主要的代码:

   public static void main(String[] args) {
        //checking for support
        if (!SystemTray.isSupported()) {
            System.out.println("System tray is not supported !!! ");
            return;
        }
        SystemTray systemTray = SystemTray.getSystemTray();
        Image image = Toolkit.getDefaultToolkit().getImage("icon.ico");

        //popupmenu
        PopupMenu trayPopupMenu = new PopupMenu();

        //1t menuitem for popupmenu
        MenuItem action = new MenuItem("Action");
        action.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                JOptionPane.showMessageDialog(null, "Action Clicked");
            }
        });
        trayPopupMenu.add(action);

        //2nd menuitem of popupmenu
        MenuItem close = new MenuItem("Close");
        close.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                System.exit(0);
            }
        });
        trayPopupMenu.add(close);

        //setting tray icon
        TrayIcon trayIcon = new TrayIcon(image, "SystemTray Demo", trayPopupMenu);
        //adjust to default size as per system recommendation 
        trayIcon.setImageAutoSize(true);

        try {
            systemTray.add(trayIcon);
        } catch (AWTException awtException) {
            awtException.printStackTrace();
        }
        System.out.println("end of main");

    }//end of main

0 个答案:

没有答案