Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Field validation in JavaFX [closed]

Tags:

javafx

fxml

I created one registration form using fxml. Now I want to implement the field validation functionality. I am trying to implement the validation for TextField but still I am not getting it.

like image 603
naresh Avatar asked Oct 02 '22 22:10

naresh


2 Answers

Unfortunately, there is no validation framework within JavaFX. Even frameworks such as Granite Data Services had troubles with bean validation with JavaFX: http://granitedataservices.com/blog/2012/11/29/thoughts-about-javafx-and-bean-validation/ (!Wayback)

If you are interested with bean validation with JavaFX, Granite generate java beans with JavaFX Property fields with bean validation enabled (you validate your java bean which is binded to your javafx components). It can be a good solution, or a good inspiration for your problem.

like image 54
zenbeni Avatar answered Oct 13 '22 12:10

zenbeni


You can validate on lost focus on the control. That is a pretty common cross-platform method...

textField.focusedProperty().addListener((observable, oldValue, newValue) ->
{
   if(textField.isFocused() == false)
   {
      LOGGER.debug("Validate on lost focus here...");
   }
});

JavaFX 8

like image 38
kervin Avatar answered Oct 13 '22 10:10

kervin