JTextField에서 사용자의 키보드 입력을 불법/금지 파일 이름 문자로 필터링하려고합니다. 이미 JTextField에서 대문자 필터를 설정했습니다.JTextField에서 사용자의 키보드 입력에서 불법적이거나 금지 된 파일 이름 문자를 필터링하는 방법은 무엇입니까?
DocumentFilter dfilter = new UpcaseFilter();
JTextField codeTF = new JTextField();
((AbstractDocument) codeTF.getDocument()).setDocumentFilter(dfilter);
다음은 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);
}
}
어떻게이 문제를 해결할 수 있습니까?
불행히도 JFormattedTextField는 _entering_ illegal 문자는 방지하지 않지만 나중에 검사하기 때문에이 목적으로는 작동하지 않습니다. –