JTextArea only with numbers, but allowing negative values
问题 I have a JTextArea which only has to accept numbers. This is my code: DocumentFilter onlyNumberFilter = new AxisJTextFilter(); final JTextArea areaTextoXMin = new JTextArea(String.valueOf(xMin)); ((AbstractDocument)areaTextoXMin.getDocument()).setDocumentFilter(onlyNumberFilter); Works OK for positive numbers, but not for negative numbers. How can I fix that? EDIT: Sorry, the AxisJTextFilter was found over the Internet and I forgot about that. Its code is: import javax.swing.text.*; import