I want to filter user's keyboard input for illegal/forbidden filename characters in JTextField. I have already set uppercase filter in JTextField.
DocumentFilter dfilter = new UpcaseFilter();
JTextField codeTF = new JTextField();
((AbstractDocument) codeTF.getDocument()).setDocumentFilter(dfilter);
Here is filter that I use to change lowercase to uppercase in JTextfield.
class UpcaseFilter 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 attr) throws BadLocationException
{
fb.replace(offset, length, text.toUpperCase(), attr);
}
}
How to I solve this problem?