如何让jTextField只能输入数字
1个回答
展开全部
text1.addKeyListener(new KeyAdapter(){
public void keyTyped(KeyEvent e){
char c = e.getKeyChar();
if(Character.isDigit(c) || c==KeyEvent.VK_BACK_SPACE || c==KeyEvent.VK_DELETE)
return;
e.consume();
}
});
public void keyPressed(KeyEvent e){
if(e.isControlDown()) e.consume();
}
public void keyTyped(KeyEvent e){
char c = e.getKeyChar();
if(Character.isDigit(c) || c==KeyEvent.VK_BACK_SPACE || c==KeyEvent.VK_DELETE)
return;
e.consume();
}
});
public void keyPressed(KeyEvent e){
if(e.isControlDown()) e.consume();
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询