This repository was archived by the owner on Feb 20, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSWTApp.java
More file actions
86 lines (61 loc) · 1.89 KB
/
SWTApp.java
File metadata and controls
86 lines (61 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package e4FileDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
/**
* ZetCode Java SWT tutorial
*
* This example shows a file dialog
*
* @author jan bodnar
* website zetcode.com
* last modified June 2009
*/
public class SWTApp {
private Shell shell;
public SWTApp(Display display) {
shell = new Shell(display);
shell.setText("FileDialog");
initUI();
shell.setSize(350, 250);
shell.setLocation(300, 300);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
public void initUI() {
final Label label = new Label(shell, SWT.NONE);
label.setText("ZetCode Java SWT tutorial");
label.setLocation(50, 50);
label.pack();
shell.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent event) {
FileDialog dialog = new FileDialog(shell, SWT.OPEN);
String[] filterNames = new String[]
{"Java sources", "All Files (*)"};
String[] filterExtensions = new String[]
{"*.java", "*"};
dialog.setFilterNames(filterNames);
dialog.setFilterExtensions(filterExtensions);
String path = dialog.open();
if (path != null) {
label.setText(path);
label.pack();
}
}
});
}
public static void main(String[] args) {
Display display = new Display();
new SWTApp(display);
display.dispose();
}
}