public void setSelectionRange(int pos, int length) {
        // Setting the selection range will not work for unattached elements.
        if (!isAttached()) {
            return;
        }

        if (length < 0) {
            throw new IndexOutOfBoundsException(
                    "Length must be a positive integer. Length: " + length);
        }
        if (pos < 0 || length + pos > getText().length()) {
            throw new IndexOutOfBoundsException("From Index: " + pos + "  To Index: "
                    + (pos + length) + "  Text Length: " + getText().length());
        }
        setSelectionRange(getElement(), pos, length);
    }
Sets the range of text to be selected.
<p>
This will only work when the widget is attached to the document and not
hidden.

@param pos    the position of the first character to be selected
@param length the number of characters to be selected
stroom-core-client-widget/src/main/java/com/google/gwt/user/client/ui/ValueBoxBase.java