-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathPopupWindowExample.java
More file actions
91 lines (78 loc) · 2.24 KB
/
PopupWindowExample.java
File metadata and controls
91 lines (78 loc) · 2.24 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
87
88
89
90
91
package lwjgui;
import lwjgui.geometry.Insets;
import lwjgui.geometry.Pos;
import lwjgui.scene.Scene;
import lwjgui.scene.Window;
import lwjgui.scene.WindowHandle;
import lwjgui.scene.WindowManager;
import lwjgui.scene.WindowThread;
import lwjgui.scene.control.Button;
import lwjgui.scene.control.Label;
import lwjgui.scene.layout.BorderPane;
import lwjgui.scene.layout.StackPane;
import lwjgui.scene.layout.VBox;
public class PopupWindowExample extends LWJGUIApplication {
public static final int WIDTH = 320;
public static final int HEIGHT = 240;
public static void main(String[] args) {
launch(args);
}
@Override
public void start(String[] args, Window window) {
// Add background pane
StackPane pane = new StackPane();
// Create vertical box
VBox vbox = new VBox();
vbox.setSpacing(8);
vbox.setAlignment(Pos.CENTER);
pane.getChildren().add(vbox);
// Create the button for the box
Button button = new Button("Click Me!");
button.setOnAction((event)-> {
popup("Test Popup");
});
// Add the components
vbox.getChildren().add(button);
// Set the scene
window.setScene(new Scene(pane, WIDTH, HEIGHT));
window.show();
}
protected static void popup(String popup) {
// Create a popup window
WindowManager.runLater(() -> {
// ManagedThread constructor must run in the main thread, we schedule it's
// execution using the WindowManager.runLater function
new WindowThread(300, 100, "Popup") {
@Override
protected void setupHandle(WindowHandle handle) {
super.setupHandle(handle);
handle.canResize(false);
}
@Override
protected void init(Window window) {
super.init(window);
window.setCanUserClose(false);
// Create root pane
BorderPane root = new BorderPane();
root.setPadding(new Insets(4,4,4,4));
// Create a label
Label l = new Label("Congratulations, You've won!");
root.setCenter(l);
// Create a button
Button b = new Button("Claim prize");
root.setBottom(b);
b.setOnAction((event)-> {
window.close();
});
// Display window
window.setScene(new Scene(root, 250, 75));
window.show();
}
}.start(); // Start the ManagedThread
});
}
@Override
protected void run() {
//
}
}