I want to make a JTextField
accept only number. And I found solution here.
((AbstractDocument)textField_time.getDocument()).setDocumentFilter(new DocumentFilter() {
@Override
public void insertString(DocumentFilter.FilterBypass fb, int offset, String str, AttributeSet a) throws BadLocationException {
fb.insertString(offset, str.replaceAll("\\D++", ""), a);
}
});
Above is my code, and alphabet can still be typed in;