Try using the DocumentFilter class. This will allow you to check the input before it is actually shown. You can also edit what I have below to check for only integers.
JTextField tf = new JTextField();
AbstractDocument d = (AbstractDocument) tf.getDocument();
d.setDocumentFilter(new DocumentFilter(){
int max = 1;
@Override
public void replace(DocumentFilter.FilterBypass fb, int offset, int length, String text, AttributeSet attrs) throws BadLocationException {
int documentLength = fb.getDocument().getLength();
if (documentLength - length + text.length() <= max)
super.replace(fb, offset, length, text.toUpperCase(), attrs);
}
});