I'm in the process of converting a JavaFX application from declaring/configuring its controls in Java code to splitting out the layout to an FXML config. The problem I'm having is that I can't locate the equivalent attribute (?) to the code's ChangeListener.
In the original Java code, I have
class TextFieldChangeListener implements ChangeListener<String> {
private boolean isRequiredDataPresent() {
return outputNameTextField.getText().length() > 0 && numOfOutputFilesTextField.getText().length() > 0;
}
@Override
public void changed( ObservableValue<? extends String> observableValue, String s, String s2 ) {
mergeButton.setDisable( ! isRequiredDataPresent() );
}
}
About the closest I can get using FXML is:
<TextField id="outputNameTextField" onKeyPressed="#textBoxOnChange" promptText="Path of merge file" GridPane.columnIndex="1" GridPane.rowIndex="3" GridPane.columnSpan="2" GridPane.rowSpan="1" />
The problem with using onKeyPressed is that it doesn't pickup pasted in values like ChangeListener does. How do I add a change listener in FXML?
FX Markup Language. In the same way that HTML is for Hypertext Markup Language, and many more acronyms that end in ML .
The fx:id is the identity associated to component in fxml to build a controller, and the id is used for css. Follow this answer to receive notifications.
There are two ways to set a controller for an FXML file. The first way to set a controller is to specify it inside the FXML file. The second way is to set an instance of the controller class on the FXMLLoader instance used to load the FXML document.
You can not do that because the value property is a sub-part of TextField. So you have to write it in your code. FXML comes only for the graphical aspects. For more information about FXML :
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With