Remove button to hide in systray, minimize the window will do it
This commit is contained in:
@@ -30,6 +30,8 @@ import java.awt.Toolkit;
|
|||||||
import java.awt.TrayIcon;
|
import java.awt.TrayIcon;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
import java.awt.event.WindowEvent;
|
||||||
|
import java.awt.event.WindowStateListener;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
import javax.swing.ImageIcon;
|
import javax.swing.ImageIcon;
|
||||||
@@ -82,6 +84,15 @@ public class GuiSwing extends JFrame implements Gui {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
sysTray = SystemTray.getSystemTray();
|
sysTray = SystemTray.getSystemTray();
|
||||||
|
if (SystemTray.isSupported()) {
|
||||||
|
addWindowStateListener(new WindowStateListener() {
|
||||||
|
public void windowStateChanged(WindowEvent e) {
|
||||||
|
if (e.getNewState() == ICONIFIED) {
|
||||||
|
hideToTray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (UnsupportedOperationException e) {
|
catch (UnsupportedOperationException e) {
|
||||||
sysTray = null;
|
sysTray = null;
|
||||||
@@ -242,6 +253,9 @@ public class GuiSwing extends JFrame implements Gui {
|
|||||||
if (sysTray != null && SystemTray.isSupported()) {
|
if (sysTray != null && SystemTray.isSupported()) {
|
||||||
sysTray.remove(trayIcon);
|
sysTray.remove(trayIcon);
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
|
setExtendedState(getExtendedState() & ~JFrame.ICONIFIED & JFrame.NORMAL); // for toFront and requestFocus to actually work
|
||||||
|
toFront();
|
||||||
|
requestFocus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -134,15 +134,6 @@ public class Working implements Activity {
|
|||||||
parent.getContentPane().add(pauseButton, constraints);
|
parent.getContentPane().add(pauseButton, constraints);
|
||||||
|
|
||||||
++currentRow;
|
++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");
|
exitAfterFrame = new JButton("Exit after this frame");
|
||||||
constraints.gridx = 2;
|
constraints.gridx = 2;
|
||||||
constraints.gridy = currentRow;
|
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 {
|
class ExitAfterAction implements ActionListener {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user