Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create and show common dialog (Error, Warning, Confirmation) in JavaFX 2.0?

How do I create and show common dialogs (Error, Warning, Confirmation) in JavaFX 2.0? I can't find any "standard" classes like Dialog, DialogBox, Message or something.

like image 993
Anton Avatar asked Nov 29 '11 11:11

Anton


People also ask

Which component provides a way to show various Dialog such as Error MESSAGE Confirmation?

The JOptionPane class is used to provide standard dialog boxes such as message dialog box, confirm dialog box and input dialog box. These dialog boxes are used to display information or get input from the user.

Does JavaFX currently provide a standard Dialog API?

A Dialog in JavaFX wraps a DialogPane and provides the necessary API to present it to end users. In JavaFX 8u40, this essentially means that the DialogPane is shown to users inside a Stage , but future releases may offer alternative options (such as 'lightweight' or 'internal' dialogs).

What is Alert in JavaFX?

An alert is a dialog which shows pre-built dialog types. You can create an alert by instantiating the javafx.scene.control.Alert class. This class is a subclass of the Dialog class.

Are JavaFX dialogs modal?

Those in-built JavaFX Dialog and Alert classes also have initOwner and initModality and showAndWait methods, so that you can set the modality for them as you wish (note that, by default, the in-built dialogs are application modal).


1 Answers

Recently released JDK 1.8.0_40 added support for JavaFX dialogs, alerts, etc. For example, to show a confirmation dialog, one would use the Alert class:

Alert alert = new Alert(AlertType.CONFIRMATION, "Delete " + selection + " ?", ButtonType.YES, ButtonType.NO, ButtonType.CANCEL); alert.showAndWait();  if (alert.getResult() == ButtonType.YES) {     //do stuff } 

Here's a list of added classes in this release:

  • javafx.scene.control.Dialog
  • javafx.scene.control.Alert
  • javafx.scene.control.TextInputDialog
  • javafx.scene.control.ChoiceDialog
like image 146
Ali Cheaito Avatar answered Nov 08 '22 22:11

Ali Cheaito