diff --git a/src/com/sheepit/client/standalone/GuiSwing.java b/src/com/sheepit/client/standalone/GuiSwing.java index 8bddb8e..03508dc 100644 --- a/src/com/sheepit/client/standalone/GuiSwing.java +++ b/src/com/sheepit/client/standalone/GuiSwing.java @@ -52,8 +52,7 @@ public class GuiSwing extends JFrame implements Gui { WORKING, SETTINGS } - private static final SystemTray TRAY = SystemTray.getSystemTray(); - + private SystemTray sysTray; private JPanel panel; private Working activityWorking; private Settings activitySettings; @@ -81,6 +80,13 @@ public class GuiSwing extends JFrame implements Gui { e1.printStackTrace(); } + try { + sysTray = SystemTray.getSystemTray(); + } + catch (UnsupportedOperationException e) { + sysTray = null; + } + URL iconUrl = getClass().getResource("/icon.png"); if (iconUrl != null) { ImageIcon img = new ImageIcon(iconUrl); @@ -214,14 +220,14 @@ public class GuiSwing extends JFrame implements Gui { } public void hideToTray() { - if (SystemTray.isSupported() == false) { + if (sysTray == null || SystemTray.isSupported() == false) { System.out.println("GuiSwing::hideToTray SystemTray not supported!"); return; } try { trayIcon = getTrayIcon(); - TRAY.add(trayIcon); + sysTray.add(trayIcon); } catch (AWTException e) { System.out.println("GuiSwing::hideToTray an error occured while trying to add system tray icon (exception: " + e + ")"); @@ -233,8 +239,10 @@ public class GuiSwing extends JFrame implements Gui { } public void restoreFromTray() { - TRAY.remove(trayIcon); - setVisible(true); + if (sysTray != null && SystemTray.isSupported()) { + sysTray.remove(trayIcon); + setVisible(true); + } } public TrayIcon getTrayIcon() {