show JavaFX Input Dialog - Java JavaFX

Java examples for JavaFX:Dialog

Description

show JavaFX Input Dialog

Demo Code


import java.io.File;
import java.util.Optional;
import javafx.scene.Node;
import javafx.scene.control.TextInputDialog;
import javafx.stage.DirectoryChooser;
import javafx.stage.Stage;

public class Main{
    public static String showInputDialog(String message, String defaultValue) {
        TextInputDialog dialog = new TextInputDialog(defaultValue);
        dialog.setContentText(message);//from w w w . j  a va  2s.  co m

        Optional<String> value = dialog.showAndWait();

        if (value.isPresent()) {
            return value.get();
        } else {
            return defaultValue;
        }
    }
}

Related Tutorials