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)。也許這是原因? –