Hello,
Could anyone please tell me why the following code does not work on LINUX but on WINDOWS and what I could do to make it work? I have tried so many workarounds but nothing really worked out, I cannot get it visible again - at least not properly! Thank you in advance!
private void formWindowIconified(java.awt.event.WindowEvent evt) {
setVisible(false);
}
public void SysTray () {
final TrayIcon trayIcon;
if (SystemTray.isSupported()) {
SystemTray tray = SystemTray.getSystemTray();
java.net.URL iconUrl = this.getClass().getResource("jack_in_box.gif");
Image image = getToolkit().getImage(iconUrl);
MouseListener mouseListener = new MouseListener() {
public void mouseClicked(MouseEvent e) {
setVisible(true);
setExtendedState(Frame.NORMAL);
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
public void mousePressed(MouseEvent e) {
}
public void mouseReleased(MouseEvent e) {
}
};
ActionListener exitListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
};
PopupMenu popup = new PopupMenu();
MenuItem defaultItem = new MenuItem("Exit");
defaultItem.addActionListener(exitListener);
popup.add(defaultItem);
trayIcon = new TrayIcon(image, "CheckInBox", popup);
trayIcon.setImageAutoSize(true);
trayIcon.addMouseListener(mouseListener);
try {
tray.add(trayIcon);
} catch (AWTException e) {
System.err.println("TrayIcon could not be added.");
}
} else {
// System Tray is not supported
}
}