Is it possible to grab the value of a JFormatedTextField by clicking on a button?
Because that is what I have been racking my brain on today. Assume a run of the mill GUI consisting of two Panels, a JFormatedTextField and a button. What the panels show is not important - importantis the TextField. in this text field is obviuosly a value to be entered and the pressed button shall kick of the processing of the value. The following I made the TextField:
JFormattedTextField NutzerID=new JFormattedTextField(NumberFormat.getIntegerInstance());
NutzerID.setFocusLostBehavior(JFormattedTextField.COMMIT);
NutzerID.setEditable(true);
And receive the value inside the Actionlistener of the Button as follows(output intended as debug):
int Label=((Number) NutzerID.getValue()).intValue();
System.out.println(Label);
Now, if I click on the button, I receive a NullpointerException inside the Actionlistener to my button.
Two things: The GUI is build using Intellijs GUI generator so I do not exactly know how the Cmponents are attached. Secondly, I am already working with a FormatedTextField but in a different Dialog. And that part works wonderful...
So I do not understand how one Button coupled FormattedTextField could work but the other not. Could it be because I did the Layout for the working FormattedTextField manually and let myself rely on the automatic layout of IntelliJ's GUI builder?
I have tried commiting (comitEdit)in the Button Actionlistener, add an Actionlistener to the TextField and adding an Focuslistener to the Textfield. Nothing worked.
Please tell me what I did wrong.