Simply create a textfield, and make each GUI class implement ValidationCandidate:
//your Dialogs must implement this interface
public class ExampleGUI implements ValidationCandidate {
public void begin(Stage primaryStage) {
VBox vBox = new VBox();
//create a textfield
TextField textField = new TextField();
//validate it
SimpleValidatorDecorator simpleValidatorDecorator = new SimpleValidatorDecorator(this);
SimpleValidator validator = new TextFieldValidator(textField, simpleValidatorDecorator);
validator.add(new MinimumFieldLengthValidator(5)); //add the various validations, as needed
validator.add(new MaximumFieldLengthValidator(12));
simpleValidatorDecorator.addValidator(validator);
//that's all!
vBox.getChildren().addAll(textField);
Scene newScene = new Scene(vBox);
newScene.getStylesheets().add("/css/stylesheet.css");
primaryStage.setScene(newScene);
primaryStage.show();
}
@Override
public void allGUIFieldsAreValid() {
System.out.println("All text boxes are valid.");
//SimpleValidation will call this method when *all* the added textfields validate
}
}
A full working example is included with the source code, which I would urge you to examine. SimpleValidator is mostly self-contained, but you will need to add Log4J to your projects dependencies. If you use Maven, a sample POM is added to the program sourcecode for ease of use. Otherwise please download Log4j and add it to your programs' libraries.