Reputation: 510
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 with DocumentListener
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 the JTextField
array and place its values into the target
array.
Upvotes: 1
Views: 217
Reputation: 205785
Adder
is an example that maintains a List<JFormattedTextField>
to enforce formatting. It uses a PropertyChangeListener
& FocusListener
to update on navigation events, such as the default key binding to Tab and Shift-Tab.
Upvotes: 4