0
我试图做一个jComoBox,允许除从数字的所有输入。但是,当我用jComoBox尝试它不工作。jComoBox输入的字符(不含数字)
我jTextFiled(但oppsite-没有数字)做到了成功:
TimeKeyTyped的代码事件i_borow jTextFiled:
private void i_borowTimeKeyTyped(java.awt.event.KeyEvent evt) {
char c = evt.getKeyChar();
if(!(Character.isDigit(c) || c == KeyEvent.VK_BACK_SPACE || c == KeyEvent.VK_DELETE)) {
evt.consume();
l_msg2.setForeground(Color.red);
} else {
l_msg2.setForeground(Color.black);
}
}
我试图做同样的jComoBox(c_title) :
private void c_titleKeyTyped(java.awt.event.KeyEvent evt) {
System.out.println("ssss");
char c = evt.getKeyChar();
System.out.println(c);
if(Character.isDigit(c)){
evt.consume();
l_noNum.setForeground(Color.red);
} else {
l_noNum.setForeground(Color.black);
}
}
该代码不起作用。 此外,这不是打印“ssss”字符串。 为什么它不能在jComboBox上工作? 谢谢。
感谢那些作品。但有一个错误:在线程“AWT-EventQueue的 - 0” java.lang.IllegalArgumentException异常异常:倒霉的位置:1 –
@DocLevi对我的作品的罚款。我怎样才能重现这个异常? –
我正在使用:AutoCompleteDecorator.decorate(JComboBox)。也许这是原因? –