Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equivalent FXML attribute to ChangeListener?

Tags:

javafx-2

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?

like image 218
Todd Avatar asked Jun 28 '13 15:06

Todd


People also ask

What does FXML stand for?

FX Markup Language. In the same way that HTML is for Hypertext Markup Language, and many more acronyms that end in ML .

What is FX ID in FXML?

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.

How do I specify a controller in FXML?

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.


1 Answers

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 :

  • http://docs.oracle.com/javafx/2/get_started/fxml_tutorial.htm
  • http://docs.oracle.com/javafx/2/fxml_get_started/jfxpub-fxml_get_started.htm
like image 136
PhilippeVienne Avatar answered Oct 16 '22 13:10

PhilippeVienne