I am trying to put the Java SystemTray icon on the gnome notification bar (I am using OpenSuse 13.2, which is using gnome 3.14).
It does not work, although SystemTray.isSupported () returns true. I do not see the icons on the screen. I was expecting it to appear next to the OpenSuse notification area.
This is the main code:
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
source share