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