Todd
Todd

Reputation: 3009

Equivalent FXML attribute to ChangeListener?

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?

Upvotes: 10

Views: 2500

Answers (1)

PhilippeVienne
PhilippeVienne

Reputation: 560

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 :

Upvotes: 5

Related Questions