This release of ScalaFX-Extras adds a new class for convenient creation of input dialogs: GenericDialogFX. You can easily add controls to he dialog then read their values after the dialog was closed

// Create a dialog
val dialog =
  new GenericDialogFX(
    title = "GenericDialogFX Demo",
    header = "Fancy description can go here."
  ) {
    // Add fields
    addCheckbox("Check me out!", defaultValue = false)
    addCheckbox("Check me too!", defaultValue = true)
  }

// Show dialog to the user
dialog.showDialog()

// Read input provided by the user
if (dialog.wasOKed) {
  val select1 = dialog.nextBoolean()
  val select2 = dialog.nextBoolean()

  println(s"Selection 1: $select1")
  println(s"Selection 2: $select2")
} else {
  println("Dialog was cancelled.")
}

The scalafx-extras-demos subproject has a more elaborated example.

Enhancements:

  • Support creation of custom dialogs, like ImageJ’s GenericDialog Issue #16
  • Let any standard dialog be displayed with a one-liner Issue #17