Click here to show the gifJava Swing DocumentFilter для UpperCase
DocumentFilter df = new DocumentFilter(){
@Override
public void insertString(DocumentFilter.FilterBypass fb, int offset,String string, AttributeSet attr) throws BadLocationException {
super.insertString(fb, offset, string.toUpperCase(), attr);
}
@Override
public void replace(DocumentFilter.FilterBypass fb, int offset, int length,String text, AttributeSet attrs) throws BadLocationException {
super.insertString(fb, offset, text.toUpperCase(), attrs);
}
};
txtCognome.setText("");
documentCognome.setDocumentFilter(dff);
Проблема заключается в том, когда я выделите текст и повторно типа; то выбранный текст не будет удален, но останется (посмотрите gif сверху).
Пожалуйста, вы можете оставить правильный код. Большое спасибо. –
Большое спасибо, теперь я решил проблему благодаря вам! Вы фантастика :-) –