public void insertString(int offs, String str, AttributeSet a) throws BadLocationException { if ((getLength() + str.length()) <= size) { super.insertString(offs, str, a); } else { System.err.println( "Tried to make field " + (getLength() + str.length()) + " characters long when max length is " + size); Toolkit.getDefaultToolkit().beep(); } }