Java Examples for com.jfoenix.validation.RequiredFieldValidator
The following java examples will help you to understand the usage of com.jfoenix.validation.RequiredFieldValidator. These source code samples are taken from different open source projects.
Example 1
| Project: JFoenix-master File: TextFieldDemo.java View source code |
@Override
public void start(Stage stage) throws Exception {
final VBox pane = new VBox();
pane.setSpacing(30);
pane.setStyle("-fx-background-color:WHITE;-fx-padding:40;");
pane.getChildren().add(new TextField());
JFXTextField field = new JFXTextField();
field.setLabelFloat(true);
field.setPromptText("Type Something");
pane.getChildren().add(field);
JFXTextField disabledField = new JFXTextField();
disabledField.setStyle(FX_LABEL_FLOAT_TRUE);
disabledField.setPromptText("I'm disabled..");
disabledField.setDisable(true);
pane.getChildren().add(disabledField);
JFXTextField validationField = new JFXTextField();
validationField.setPromptText("With Validation..");
RequiredFieldValidator validator = new RequiredFieldValidator();
validator.setMessage("Input Required");
validator.setIcon(GlyphsBuilder.create(FontAwesomeIconView.class).glyph(FontAwesomeIcon.WARNING).size(EM1).styleClass(ERROR).build());
validationField.getValidators().add(validator);
validationField.focusedProperty().addListener(( o, oldVal, newVal) -> {
if (!newVal) {
validationField.validate();
}
});
pane.getChildren().add(validationField);
JFXPasswordField passwordField = new JFXPasswordField();
passwordField.setStyle(FX_LABEL_FLOAT_TRUE);
passwordField.setPromptText("Password");
validator = new RequiredFieldValidator();
validator.setMessage("Password Can't be empty");
validator.setIcon(GlyphsBuilder.create(FontAwesomeIconView.class).glyph(FontAwesomeIcon.WARNING).size(EM1).styleClass(ERROR).build());
passwordField.getValidators().add(validator);
passwordField.focusedProperty().addListener(( o, oldVal, newVal) -> {
if (!newVal) {
passwordField.validate();
}
});
pane.getChildren().add(passwordField);
final Scene scene = new Scene(pane, 600, 400, Color.WHITE);
scene.getStylesheets().add(TextFieldDemo.class.getResource("/css/jfoenix-components.css").toExternalForm());
stage.setTitle("JFX TextField Demo ");
stage.setScene(scene);
stage.setResizable(false);
stage.show();
}Example 2
| Project: mytime-master File: ManagerGuildMainViewController.java View source code |
/**
* Create new guild dialog.
*/
private void initCreateNewGuildDialog() {
JFXDialogLayout layout = new JFXDialogLayout();
Label lblHeader = new Label("Opret et nyt laug", new ImageView(new Image("/mytime/gui/view/css/Add.png")));
lblHeader.setFont(Font.font(20));
GridPane gridPane = new GridPane();
gridPane.setPadding(new Insets(5));
gridPane.setHgap(5);
gridPane.setVgap(25);
ColumnConstraints column1 = new ColumnConstraints(100);
ColumnConstraints column2 = new ColumnConstraints(50, 150, 300);
column2.setHgrow(Priority.ALWAYS);
gridPane.getColumnConstraints().addAll(column1, column2);
Label fNameLbl = new Label("Navn:");
JFXTextField guildName = new JFXTextField();
guildName.focusedProperty().addListener(( o, oldVal, newVal) -> {
if (!newVal) {
paintInputs(guildName);
}
});
RequiredFieldValidator rfv = new RequiredFieldValidator();
rfv.setMessage("Navn kan ikke være tomt");
rfv.setIcon(new Icon(AwesomeIcon.WARNING, "1em", ";", "error"));
guildName.getValidators().add(rfv);
Label lNameLbl = new Label("Vælg afdeling:");
ValidationDecoration iconDecorator = new GraphicValidationDecoration();
JFXComboBox<Location> guildLocation = new JFXComboBox();
guildLocation.setPromptText("Vælg en lokation hvor det laug befinder sig");
try {
guildLocation.getItems().addAll(Model.getInstance().getAllLocations());
} catch (SQLException ex) {
ex.printStackTrace();
}
guildLocation.focusedProperty().addListener(( o, oldVal, newVal) -> {
iconDecorator.removeDecorations(guildLocation);
});
JFXButton saveButt = new JFXButton("Gem");
saveButt.setOnAction( e -> {
boolean b = paintInputs(guildName);
if (guildLocation.getSelectionModel().getSelectedItem() == null || !b) {
iconDecorator.removeDecorations(guildLocation);
iconDecorator.applyValidationDecoration(ValidationMessage.error(guildLocation, ""));
} else {
try {
Group newGroup = mgrModel.createNewGuild(guildName.getText().trim(), guildLocation.getSelectionModel().getSelectedItem());
dialogCreateNewGuild.close();
Platform.runLater(() -> {
try {
masonryPaneGuilds.getChildren().add(getOneGuild(newGroup));
} catch (IOException ex) {
ex.printStackTrace();
}
});
} catch (SQLException ex) {
ex.printStackTrace();
}
}
});
GridPane.setHalignment(fNameLbl, HPos.RIGHT);
gridPane.add(fNameLbl, 0, 0);
GridPane.setHalignment(lNameLbl, HPos.RIGHT);
gridPane.add(lNameLbl, 0, 1);
GridPane.setHalignment(guildName, HPos.LEFT);
gridPane.add(guildName, 1, 0);
GridPane.setHalignment(guildLocation, HPos.LEFT);
gridPane.add(guildLocation, 1, 1);
GridPane.setHalignment(saveButt, HPos.RIGHT);
gridPane.add(saveButt, 1, 2);
layout.setHeading(lblHeader);
layout.setBody(gridPane);
dialogCreateNewGuild = new JFXDialog(stackPane, layout, JFXDialog.DialogTransition.LEFT);
dialogCreateNewGuild.setOnDialogClosed( e -> {
iconDecorator.removeDecorations(guildLocation);
guildName.resetValidation();
guildName.clear();
guildLocation.getSelectionModel().clearSelection();
guildName.setUnFocusColor(Paint.valueOf("BLACK"));
});
}