java - Javafx Textfield - getText() empty? -


i have textfield in javafx created in fxml. links variable named "thesholdbox" (as seen below, instantiation not show). have field listening keyevents, whenever enter values in field, "gettext()" returns empty string.

java code:

@fxml public void threshbox(keyevent e) {     //always empty unless set manually using "thresholdbox.settext("testing")" or     string newvalue = thresholdbox.gettext();     system.out.println("text: " + newvalue); } 

fxml:

<textfield fx:id="thresholdbox" layoutx="255.0" layouty="5.0" onkeytyped="#threshbox" prefheight="31.0" prefwidth="91.0" prompttext="0.00" /> 

screenshot example:

enter image description here

now, expect thresholdbox.gettext() return "test." testing shows code being triggered, each pass gives me empty string. know why is? i'm new javafx, , while didn't see in documentation why problem happening, it's entirely possible missed something.

let me know if can make question clearer.

thank you!

update: relevant code -

//here 2 other places thresholdbox used.  //i cropped irrelevant variable declarations, since not interact thresholdbox.   //class variable @fxml textfield thresholdbox;  @override public void initialize(url url, resourcebundle rb) {     thresholdbox = new textfield(); } 

it looks shouldn't have been using "thresholdbox = new textfield();" in initialize function, overriding fxml textfield.

thank you, james_d, answer.


Comments