Added a small popup menu to StatusTrayIcon and loading it in Startup

This commit is contained in:
Kai S. K. Engelbart 2019-12-04 07:50:59 +01:00
parent fbe2d0d0b0
commit 378a83638a
2 changed files with 20 additions and 2 deletions

View File

@ -64,6 +64,7 @@ public class Startup {
EventQueue.invokeLater(() -> {
try {
ChatWindow frame = new ChatWindow(client, localDB);
new StatusTrayIcon().show();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();

View File

@ -2,6 +2,8 @@ package envoy.client.ui;
import java.awt.AWTException;
import java.awt.Image;
import java.awt.MenuItem;
import java.awt.PopupMenu;
import java.awt.SystemTray;
import java.awt.Toolkit;
import java.awt.TrayIcon;
@ -24,9 +26,24 @@ public class StatusTrayIcon {
if (!SystemTray.isSupported()) throw new EnvoyException("The Envoy tray icon is not supported.");
Image img = Toolkit.getDefaultToolkit().createImage(getClass().getResource("envoy_logo.png"));
TrayIcon trayIcon = new TrayIcon(img, "Envoy Client");
trayIcon = new TrayIcon(img, "Envoy Client");
trayIcon.setImageAutoSize(true);
trayIcon.setToolTip("You are notified if you have unread messages.");
PopupMenu popup = new PopupMenu();
MenuItem exitMenuItem = new MenuItem("Exit");
exitMenuItem.addActionListener((evt) -> System.exit(0));
popup.add(exitMenuItem);
trayIcon.setPopupMenu(popup);
}
/**
* Makes this {@link StatusTrayIcon} appear in the system tray.
* @throws EnvoyException
*/
public void show() throws EnvoyException {
try {
SystemTray.getSystemTray().add(trayIcon);
} catch (AWTException e) {