If I have many JTextFields on the same screen and want to have 1 listener for all of them:
i.e. myJTextField1.addActionListener(this);
myJTextField2.addActionListener(this);
.
.
myJTextField15.addActionListener(this);
How can I tell which JTextField caused the action event when I arrive at "actionPerformed":
public void actionPerformed(ActionEvent e) {
}
I have tried the following in this "actionPerformed":
JTextField source = (JTextField)(e.getSource());
String strTextFieldName = source.getName();
The above returns "null" for strTextFieldName
I was hoping that strTextField name would return "myJTextField1 or myJTextField2, etc.
What do I need to do?
Related question: When I have a screen of JLabels and JTextFields, is there normally different listener methods set up on for each JTextField or just 1 listener method with a bunch of "if" statements to tell which JTextField caused the action
Thanks.
------------------
i.e. myJTextField1.addActionListener(this);
myJTextField2.addActionListener(this);
.
.
myJTextField15.addActionListener(this);
How can I tell which JTextField caused the action event when I arrive at "actionPerformed":
public void actionPerformed(ActionEvent e) {
}
I have tried the following in this "actionPerformed":
JTextField source = (JTextField)(e.getSource());
String strTextFieldName = source.getName();
The above returns "null" for strTextFieldName
I was hoping that strTextField name would return "myJTextField1 or myJTextField2, etc.
What do I need to do?
Related question: When I have a screen of JLabels and JTextFields, is there normally different listener methods set up on for each JTextField or just 1 listener method with a bunch of "if" statements to tell which JTextField caused the action
Thanks.
------------------