class DocFilter extends DocumentFilter{
public void insertString(FilterBypass fb, int offset, String string, AttributeSet attr) throws BadLocationException {
fb.insertString(offset, string.replaceAll("\\n", ""), attr);
}
public void replace(FilterBypass fb, int offset, int length, String string, AttributeSet attr) throws BadLocationException {
fb.insertString(offset, string.replaceAll("\\n", ""), attr);
}
}
Этот код хорошо работает