Scene scene = new Scene(vBox, 320, 100);
final Dialog dialog = new Dialog(title, owner, scene);
final TextField textInput = new TextField();
textInput.setOnKeyPressed(new EventHandler<KeyEvent>()
{
@Override
public void handle(javafx.scene.input.KeyEvent event)
{
if (KeyCode.ENTER.equals(event.getCode()))
{
Dialogs.textInput = textInput.getText();
dialog.close();
response = Response.YES;
}
}
});
Button btnOK = new Button("OK");
btnOK.setOnAction(new EventHandler<ActionEvent>()
{
@Override
public void handle(ActionEvent e)
{
Dialogs.textInput = textInput.getText();
dialog.close();
response = Response.YES;
}
});
Button btnCancel = new Button("Cancel");
btnCancel.setOnAction(new EventHandler<ActionEvent>()
{
@Override
public void handle(ActionEvent e)
{
dialog.close();
response = Response.NO;
}
});
HBox hBox = new HBox();
hBox.setAlignment(Pos.CENTER);
hBox.setSpacing(10);
hBox.setPadding(new Insets(10));
hBox.getChildren().addAll(btnOK, btnCancel);
if (message != null && message.length() > 0)
{
vBox.getChildren().add(new Label(message));
}
vBox.getChildren().add(textInput);
vBox.getChildren().add(hBox);
dialog.showDialog();
textInput.requestFocus();
return response;
}