I used to make my UI by making declaring new JTextField
in a for cycle while attaching an action listener by anon class to each JTextField
, which means that you have to press enter fire an event which will read the text of the field and put it into an array here is the code
Getting data from JTextField that is one of several local variables without a few minor changes . Now I have to modify it to so that i press a button like Apply in order to have values written into an array. While I found two ways to do this wonder what is the optimal way to do this .
The horrible way . Create an array that acts as temporary storage , replace
ActionListener
s withDocumentListener
s that will place the values into this temp array . And a button that will on press iterate through the the temp array placing its values into the target array.A better way which I found while searching , create a
JTextField
array as public and simply have a button that will on press iterate through theJTextField
array and place its values into the target array.