public void insertString(int offset, String str, AttributeSet attrs) throws BadLocationException {
        if (str != null && getLength() + str.length() > max) {
            Toolkit.getDefaultToolkit().beep();
        } else {
            super.insertString(offset, str, attrs);
        }
    }