I have this TextField in FXMLDocument.fxml:
<TextField fx:id="searchBox" onKeyPressed="#updateText">
<StackPane.margin>
<Insets left="60.0" right="30.0" top="50.0" />
</StackPane.margin>
</TextField>
The FXML document (where the above code resides) has the controller class named FXMLDocumentController.java. Inside this, I have the following code:
public class FXMLDocumentController {
public TextField searchBox;
@FXML
public void updateText (KeyEvent e) {
System.out.println(searchBox.getText());
}
}
Note that the searchBox
property is public
. When I set it to private
, my code throws an Exception at runtime. I have seen people specifying the "event bounded property" as private
in Stack Overflow answers (here's one). Seeing those answers, I assume that specifying a property as private
should not give any error. What's wrong with my code then?