Reputation: 11
We are developing an application in Java Swing.
We have a text field and a combo box. The combo box values should be populated from DB based on the value entered in the text field.
The text field length is 4 characters. So, user can enter any value between 1 to 9999.
Which listener would be used to identify that the user has completed their entry in the text field so that I can populate the combo box?
Upvotes: 1
Views: 97
Reputation: 321
Use the textField.getDocument().addDocumentListener(new DocumentListener()
textField.getDocument().addDocumentListener(new DocumentListener() {
public void changedUpdate(DocumentEvent e) {
//TODO
}
public void removeUpdate(DocumentEvent e) {
//TODO
}
public void insertUpdate(DocumentEvent e) {
//TODO
}
Upvotes: 1
Reputation: 168825
..the user has completed his entry in the text field so that i can populate the combobox.
An ActionListener
. When the user is done, they hit the enter key and an action event will be fired. But..
..user can enter any value between 1 to 9999.
This sounds better suited to a JSpinner
using a SpinnerNumberModel
and a ChangeListener
to register selecting a different number.
Upvotes: 3