-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathAlertBox.java
More file actions
36 lines (27 loc) · 1.09 KB
/
AlertBox.java
File metadata and controls
36 lines (27 loc) · 1.09 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
package JavaFXDemo;
import javafx.stage.*;
import javafx.scene.*;
import javafx.scene.layout.*;
import javafx.scene.control.*;
import javafx.geometry.*;
//AlertBox displays message to the user
public class AlertBox {
public static void display(String title, String message){
Stage window = new Stage();
window.initModality(Modality.APPLICATION_MODAL);//doesn't allow user to interact with other window until
//finished with this one
window.setTitle(title);
window.setMinWidth(250);
Label label = new Label();
label.setText(message);//will set the message to the message you pass in
Button closeButton = new Button("Close the window");
closeButton.setOnAction(e -> window.close());
VBox layout = new VBox(10);
layout.getChildren().addAll(label, closeButton);
layout.setAlignment(Pos.CENTER);
Scene scene = new Scene(layout);
window.setScene(scene);
window.showAndWait();//goes together with Modality, doesn't let user interact with other window until this one
//is closed
}
}