Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Pazderski2019-06-03 17:19:32 -0400
committerPaul Pazderski2019-06-04 18:22:07 -0400
commit9c2ad38d59e0a97007f356b38de17ea8524544e8 (patch)
treef1a8aa90f7fbd7db163cc3251bce954cfb05e7be
parentd7178f44534e3d0cb04f49ba4c5a0a04b39d9313 (diff)
downloadeclipse.platform.swt-9c2ad38d59e0a97007f356b38de17ea8524544e8.tar.gz
eclipse.platform.swt-9c2ad38d59e0a97007f356b38de17ea8524544e8.tar.xz
eclipse.platform.swt-9c2ad38d59e0a97007f356b38de17ea8524544e8.zip
Bug 547938 - [Snippets] should not use System.exit
A Snippet calling System.exit will also exit the SnippetLauncher or the SnippetExplorer (depending on selected runner).
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet133.java2
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet337.java35
2 files changed, 32 insertions, 5 deletions
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet133.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet133.java
index a0c6bf81a3..add8f3750b 100644
--- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet133.java
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet133.java
@@ -90,7 +90,7 @@ public class Snippet133 {
new MenuItem(fileMenu, SWT.SEPARATOR);
item = new MenuItem(fileMenu, SWT.PUSH);
item.setText("E&xit");
- item.addSelectionListener(widgetSelectedAdapter(e-> System.exit(0)));
+ item.addSelectionListener(widgetSelectedAdapter(e-> shell.dispose()));
shell.open();
while (!shell.isDisposed()) {
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet337.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet337.java
index 7941de36ba..f0b502898e 100644
--- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet337.java
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet337.java
@@ -21,6 +21,8 @@ package org.eclipse.swt.snippets;
*/
import java.awt.*;
import java.awt.Canvas;
+import java.awt.event.*;
+import java.awt.event.WindowEvent;
import javax.swing.*;
@@ -32,12 +34,14 @@ import org.eclipse.swt.widgets.*;
public class Snippet337 {
-public static void main(String args[]) {
- final Display display = new Display();
+static Display display;
+public static void main(String args[]) {
+ display = new Display();
EventQueue.invokeLater(() -> {
JFrame mainFrame = new JFrame("Main Window");
- mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ mainFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
+ mainFrame.addWindowListener(new Snippet337.CloseListener());
JPanel mainPanel = new JPanel();
mainPanel.setLayout(new FlowLayout());
JButton launchBrowserButton = new JButton("Launch Browser");
@@ -74,5 +78,28 @@ public static void main(String args[]) {
if (!display.readAndDispatch()) display.sleep();
}
}
-
+private static class CloseListener implements WindowListener {
+ @Override
+ public void windowClosed(WindowEvent e) {
+ display.asyncExec(() -> display.dispose());
+ }
+ @Override
+ public void windowOpened(WindowEvent e) {
+ }
+ @Override
+ public void windowClosing(WindowEvent e) {
+ }
+ @Override
+ public void windowIconified(WindowEvent e) {
+ }
+ @Override
+ public void windowDeiconified(WindowEvent e) {
+ }
+ @Override
+ public void windowActivated(WindowEvent e) {
+ }
+ @Override
+ public void windowDeactivated(WindowEvent e) {
+}
+}
}

Back to the top