Use DocumentFilter to change the text as it appears.
Not the most beautiful source, and it is not 100% correct, just showing how it works. See original here
((AbstractDocument)textField.getDocument()).setDocumentFilter(new UppercaseDocumentFilter()); class UppercaseDocumentFilter extends DocumentFilter { public void insertString(DocumentFilter.FilterBypass fb, int offset, String text, AttributeSet attr) throws BadLocationException { fb.insertString(offset, text.toUpperCase(), attr); } public void replace(DocumentFilter.FilterBypass fb, int offset, int length, String text, AttributeSet attrs) throws BadLocationException { fb.replace(offset, length, text.toUpperCase(), attrs); } }
source share