I currently have a dialog with four text fields from which the input is collected. When the input does not meet my requirements, the dialog should remain open and display an error message. I currently have the following code:
dlg.setResultConverter(dialogButton -> { if (dialogButton == createButtonType) { ArrayList<String> returnList = getInput(); if (returnList != null) { return returnList; } else { dlg.showAndWait(); } } return null; }); Optional<ArrayList<String>> result = dlg.showAndWait(); result.ifPresent(customerDetails -> {
The getInput() method retrieves text from TextFields and checks for certain requirements. When the input passes, four lines are placed in an ArrayList<String> . Otherwise, the method returns null . As you can see, the result converter checks to see if the null method returned. If it is not, it simply returns an ArrayList<String> .
But, when the check fails, the dialog should remain open. It works with dlg.showAndWait() , but the disadvantage is that it causes an error: java.lang.IllegalStateException: Stage already visible . (it continues to work, but getting the error is not the way it should be)
My question is: does anyone know how to do this without causing an error?
Note. I am using JavaFX 8 (JDK 1.8.0_40), which has built-in dialog features.
source share