Dialog<String> d = DialogFactory.createInput(null, "Input your avatar name", "The name will be displayed on public conversations.", "My InputDialog", "John");
Action a = d.getActionMap().get(DialogActionType.OK);
a.setHandler(evt -> {
String input = d.getResultConverter().call(DialogActionType.OK);
if (input.length() < 4)
{
DialogFactory.showError(null, "The name must have a minimum of 4 characters!", null, "Name Length Error!");
d.getRootPane().lookup(".text-field").requestFocus();
return;
}
d.setResult(input);
d.hide();
});
d.showAndWait();
System.out.println("Result: " + d.getResult());
In case you have to access the controls of the dialog directly it's recommended to create your own controller by extending the related base controller - in this case
DialogFactory.InputDialogController
. To achieve this the member controls of the base controller class are declared as protected
.
public static class CustomInputDialogController extends DialogFactory.InputDialogController
{
@Override
public Dialog createDialog(Window owner, String message, String description, String title, String defaultInput)
{
Dialog<String> d = super.createDialog(owner, message, description, title, defaultInput);
Action a = d.getActionMap().get(DialogActionType.OK);
a.setHandler(evt -> {
String input = d.getResultConverter().call(DialogActionType.OK);
if (input.length() < 4)
{
DialogFactory.showError(null, "The name must have a minimum of 4 characters!", null, "Name Length Error!");
inputControl.requestFocus();
return;
}
d.setResult(input);
d.hide();
});
return d;
}
}
Usage is straight forward.
Dialog<String> d = new CustomInputDialogController().createDialog(owner, "Input your avatar name", "The name will be displayed on public conversations.", "My InputDialog", "John");
d.showAndWait();
-sfx-fxml-content
. Additionally it's possible to use different layouts
on different operating systems - for this special pseudo classes are supported.
Regular input dialog with long text.
Dialog<String> d = DialogFactory.createInput(null, "Input your pretty long text below", "Some additional description...", "My InputDialog", "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.");
d.showAndWait();
Customized input dialog with a text area for long text. To work properly class member controls of the base controller with related fx:id
have to be specified within the provided FXML file.
Dialog<String> d = DialogFactory.createInput(null, "Input your pretty long text below", "Some additional description...", "My InputDialog", "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.");
d.getRootPane().setStyle("-sfx-fxml-content: url(\"/com/jyloo/syntheticafx/demo/resources/fxml/inputDialog.fxml\");");
d.showAndWait();
ResourceManager
. Custom bundles should be loaded on appliaction startup.
SyntheticaFX skin = new SyntheticaFXModena();
skin.init();
ResourceManager.addBundle("com/jyloo/syntheticafx/demo/resources/dialog");
Content of the default bundle:
ConfirmDialog.title.text=Confirmation
DetailsDialog.title.text=Details
DetailsDialog.detailsButton.hideText=Hide Details
DetailsDialog.detailsButton.showText=Show Details
ErrorDialog.title.text=Error
InfoDialog.title.text=Information
InputDialog.title.text=Input
LoginDialog.title.text=Login
LoginDialog.userName.text=Username
LoginDialog.password.text=Password
WarningDialog.title.text=Warning
DialogAction.cancel.text=Cancel
DialogAction.close.text=Close
DialogAction.no.text=No
DialogAction.ok.text=OK
DialogAction.yes.text=Yes