[英]Listener on JTextField to detect completion of data entry
We are developing an application in Java Swing. 我们正在使用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.
组合框值应根据在文本字段中输入的值从DB填充。
The text field length is 4 characters. 文本字段的长度为4个字符。 So, user can enter any value between 1 to 9999.
因此,用户可以输入1到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? 哪个侦听器将用于标识用户已完成其在文本字段中的输入,以便我可以填充组合框?
..the user has completed his entry in the text field so that i can populate the combobox.
..用户已完成其在文本字段中的输入,以便我可以填充组合框。
An ActionListener
. 一个
ActionListener
。 When the user is done, they hit the enter key and an action event will be fired. 完成用户操作后,他们按Enter键,将触发一个动作事件。 But..
但..
..user can enter any value between 1 to 9999.
..用户可以输入1到9999之间的任何值。
This sounds better suited to a JSpinner
using a SpinnerNumberModel
and a ChangeListener
to register selecting a different number. 这听起来更适合使用
SpinnerNumberModel
和ChangeListener
注册选择其他数字的JSpinner
。
Use the textField.getDocument().addDocumentListener(new DocumentListener() 使用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
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.