java.lang.Object
com.dua3.utility.fx.controls.Validator
The Validator class is used for validating controls in a JavaFX application. It provides methods for setting
validation rules for different types of controls, such as TextInputControl and Control. It also allows for
custom validation rules to be set.
The Validator class supports the use of a ResourceBundle for looking up message texts. If a ResourceBundle is provided during initialization, it will be used to retrieve the messages for validation errors. Otherwise, the message will be used as is.
The Validator class also supports decorating nodes with invalid values. When a control fails validation, an icon and tooltip can be added to the control to indicate the validation error.
The Validator class is meant to be used in a JavaFX application and should be initialized with a valid ResourceBundle if localized validation messages are required.
-
Eigenschaftsübersicht
EigenschaftenTypEigenschaftBeschreibungReturns the read-only boolean property indicating the validity of all controls. -
Konstruktorübersicht
KonstruktorenKonstruktorBeschreibungCreates a Validator instance without assigning a resource bundle.Validator(@Nullable ResourceBundle resources) ^ Creates a Validator instance. -
Methodenübersicht
Modifizierer und TypMethodeBeschreibungvoidaddCheck(Control c, String message, BooleanSupplier test, Observable... trigger) Custom validation.voidaddCheck(Control c, String message, ObservableValue<Boolean> test) Custom validation.voidaddValidation(@Nullable Button button) Add validation for a button.voidRemove all validation decorations from controls.voiddisallowEmpty(TextInputControl c, String message) Add a rule that assures the control is not empty.voiddispose()Run cleanup actions.voidFocuses the first control.voidFocuses the first control with an invalid validation result.booleanCheck if decorations are enabled.voidsetDecorateNodes(boolean decorateNodes) Set to true to enable decorating nodes with invalid values.voidsetIconSize(int sz) Set icon size.voidsetRegex(TextInputControl c, String message, String regex) Add a rule that assures the content matches a regular expression.voidValidate all rules of this validator, update decorations, and update value of validProperty.Returns the read-only boolean property indicating the validity of all controls.
-
Eigenschaftsdetails
-
valid
Returns the read-only boolean property indicating the validity of all controls.- Siehe auch:
-
-
Konstruktordetails
-
Validator
public Validator()Creates a Validator instance without assigning a resource bundle. -
Validator
^ Creates a Validator instance.- Parameter:
resources- the resource bundle to look up message texts
-
-
Methodendetails
-
dispose
public void dispose()Run cleanup actions. -
disallowEmpty
Add a rule that assures the control is not empty.- Parameter:
c- the controlmessage- the message to display if validation fails
-
setRegex
Add a rule that assures the content matches a regular expression.- Parameter:
c- the controlmessage- the message to display if validation failsregex- the regular expression to test the control's text
-
addCheck
Custom validation.- Parameter:
c- the controlmessage- the message to display if validation failstest- the test to perform the validationtrigger- theObservables that trigger validation
-
addCheck
Custom validation.- Parameter:
c- the controlmessage- the message to display if validation failstest- ObservableValue that triggers updates and provides the validation result
-
validateAll
public void validateAll()Validate all rules of this validator, update decorations, and update value of validProperty. -
clearDecorations
public void clearDecorations()Remove all validation decorations from controls. -
setDecorateNodes
public void setDecorateNodes(boolean decorateNodes) Set to true to enable decorating nodes with invalid values.- Parameter:
decorateNodes- true, if decoration shall be added to controls with invalid values
-
isDecorateNodes
public boolean isDecorateNodes()Check if decorations are enabled.- Gibt zurück:
- true, if decorations are enabled
-
setIconSize
public void setIconSize(int sz) Set icon size.- Parameter:
sz- the new size
-
addValidation
Add validation for a button. If validation is added to a button, the validation will be performed when the button is pressed, and if validation fails, the button clicked event will be consumed.- Parameter:
button- the button to add validation to
-
focusFirst
public void focusFirst()Focuses the first control. -
focusFirstInvalid
public void focusFirstInvalid()Focuses the first control with an invalid validation result. -
validProperty
Returns the read-only boolean property indicating the validity of all controls.- Gibt zurück:
- the validProperty
-