February 10, 2023

JavaFX creating Dialog

Pre-request

1
2
3
import javafx.scene.control.Dialog;
import javafx.scene.control.ButtonType;
import javafx.scene.control.ButtonBar.ButtonData;

Method 1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
public class SignupSuccessDialog extends Dialog<List<String>>
{
public SignupSuccessDialog()
{
this.getDialogPane().getButtonTypes().addAll(ButtonType.OK);
}
}

public class main extends Application
{
public static void main (String [] args)
{
launch();
}

@Override
public void start(Stage primaryStage)
{
SignupSuccessDialog myDialog = new SignupSuccessDialog();
myDialog.setContentText("Signup Success!");
myDialog.showAndWait();
}
}

Method 2

1
2
3
4
5
6
7
8
Dialog<String> dialog = new Dialog<String>();
ButtonType type = new ButtonType("OK", ButtonData.OK_DONE);

//Setting the content of the dialog
dialog.setContentText("Signup Success");
//Adding buttons to the dialog pane
dialog.getDialogPane().getButtonTypes().add(type);
dialog.showAndWait();


Reference

About this Post

This post is written by Andy, licensed under CC BY-NC 4.0.

#Java#JavaFX