diff --git a/src/com/sheepit/client/standalone/GuiSwing.java b/src/com/sheepit/client/standalone/GuiSwing.java index 03508dc..b5cfb20 100644 --- a/src/com/sheepit/client/standalone/GuiSwing.java +++ b/src/com/sheepit/client/standalone/GuiSwing.java @@ -30,6 +30,8 @@ import java.awt.Toolkit; import java.awt.TrayIcon; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.WindowEvent; +import java.awt.event.WindowStateListener; import java.net.URL; import javax.swing.ImageIcon; @@ -82,6 +84,15 @@ public class GuiSwing extends JFrame implements Gui { try { sysTray = SystemTray.getSystemTray(); + if (SystemTray.isSupported()) { + addWindowStateListener(new WindowStateListener() { + public void windowStateChanged(WindowEvent e) { + if (e.getNewState() == ICONIFIED) { + hideToTray(); + } + } + }); + } } catch (UnsupportedOperationException e) { sysTray = null; @@ -242,6 +253,9 @@ public class GuiSwing extends JFrame implements Gui { if (sysTray != null && SystemTray.isSupported()) { sysTray.remove(trayIcon); setVisible(true); + setExtendedState(getExtendedState() & ~JFrame.ICONIFIED & JFrame.NORMAL); // for toFront and requestFocus to actually work + toFront(); + requestFocus(); } } diff --git a/src/com/sheepit/client/standalone/swing/activity/Working.java b/src/com/sheepit/client/standalone/swing/activity/Working.java index 4446712..3e9e9af 100644 --- a/src/com/sheepit/client/standalone/swing/activity/Working.java +++ b/src/com/sheepit/client/standalone/swing/activity/Working.java @@ -134,15 +134,6 @@ public class Working implements Activity { parent.getContentPane().add(pauseButton, constraints); ++currentRow; - //Add hide button if os supports it - if (SystemTray.isSupported()) { - JButton hideButton = new JButton("Hide window"); - hideButton.addActionListener(new HideAction()); - constraints.gridx = 1; - constraints.gridy = currentRow; - parent.getContentPane().add(hideButton, constraints); - } - exitAfterFrame = new JButton("Exit after this frame"); constraints.gridx = 2; constraints.gridy = currentRow; @@ -230,15 +221,6 @@ public class Working implements Activity { } } - class HideAction implements ActionListener { - @Override - public void actionPerformed(ActionEvent e) { - if (parent != null) { - parent.hideToTray(); - } - } - } - class ExitAfterAction implements ActionListener { @Override public void actionPerformed(ActionEvent e) {