[英]How to add the same KeyTypedEvent for all JTextFields
I have multiple textfields in my GUI, but all of them should only accept numbers, I created this following event for one of them, but how could I apply it to all TextFields?我的 GUI 中有多个文本字段,但它们都应该只接受数字,我为其中一个创建了以下事件,但是如何将它应用于所有文本字段?
private void jtf1KeyTyped(java.awt.event.KeyEvent evt) {
char c = evt.getKeyChar();
if (Character.isDigit(c)) {
} else {
evt.consume();
}
}
I have multiple textfields in my GUI, but all of them should only accept numbers, I created this following event for one of them, but how could I apply it to all TextFields?我的 GUI 中有多个文本字段,但它们都应该只接受数字,我为其中一个创建了以下事件,但是如何将它应用于所有文本字段?
private void jtf1KeyTyped(java.awt.event.KeyEvent evt) {
char c = evt.getKeyChar();
if (Character.isDigit(c)) {
} else {
evt.consume();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.