I am trying to write a function that can input a matrix of any size using a GridLayout, but I\'m stuck since I can\'t find an appropriate way of extracting the JTextField va
JTextField
layed by GridLayout
or
add there putClientProperty
and to add identifier Row a Column from GridLayout
put JTextField
to the HashMap
I would be preferring putClientProperty
(you can to multiplay number or additional infos.., number of separate putClientProperty
isn't somehow reduced)
depends of (not clear) desing, you can to add ActionListener
to JTextField
(accelerator is ENTER key
) or DocumentListener
virtual example, code example for JButton
and ActionListener
, putClientProperty
is accesible from all methods or Listeners
added to JTextField
in the loop
buttons[i][j].putClientProperty("column", i);
buttons[i][j].putClientProperty("row", j);
buttons[i][j].addActionListener(new MyActionListener());
and get from ActionListener (for example)
public class MyActionListener implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
JButton btn = (JButton) e.getSource();
System.out.println("clicked column " + btn.getClientProperty("column")
+ ", row " + btn.getClientProperty("row"));
}