Good day!
I am developing a program using JavaFX SDK. I wanted to have a message box like in C#:
DialogResult rs = MessageBox.showDialog(\"Mess
This is a very simple example : Alert alert = new Alert(AlertType.CONFIRMATION, "Are you sure you want to proceed?");
Here is another simple alternative: https://sites.google.com/site/martinbaeumer/programming/open-source/fxmessagebox
Surprising that there is still no standard message box available in JavaFX 2.2
Use the namespace:
import javafx.scene.control.Alert;
Calling from main thread:
public void showAlert() {
Alert alert = new Alert(Alert.AlertType.INFORMATION);
alert.setTitle("Message Here...");
alert.setHeaderText("Look, an Information Dialog");
alert.setContentText("I have a great message for you!");
alert.showAndWait();
}
Calling from not main thread:
public void showAlert() {
Platform.runLater(new Runnable() {
public void run() {
Alert alert = new Alert(Alert.AlertType.INFORMATION);
alert.setTitle("Message Here...");
alert.setHeaderText("Look, an Information Dialog");
alert.setContentText("I have a great message for you!");
alert.showAndWait();
}
});
}
https://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/Alert.html
The Alert class subclasses the Dialog class, and provides support for a number of pre-built dialog types that can be easily shown to users to prompt for a response.
So the code looks something like
Alert alert = new Alert(AlertType.INFORMATION);
alert.setTitle("Message Here...");
alert.setHeaderText("Look, an Information Dialog");
alert.setContentText("I have a great message for you!");
alert.showAndWait().ifPresent(rs -> {
if (rs == ButtonType.OK) {
System.out.println("Pressed OK.");
}
});
MessageBox on JavaFX 2.2 by OSS is here
I think it will help you.
MessageBox.show(primaryStage,
"Message Body",
"Message Title",
MessageBox.ICON_INFORMATION | MessageBox.OK | MessageBox.CANCEL);
At the moment I use this library for showing Dialogs. Maybe it can be of use for you:
https://github.com/4ntoine/JavaFxDialog