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 ww w.  j a  v  a  2 s .  c o m*/

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

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

Related Tutorials