TextWithMnemonic (int index) { if (index == mnemonicIndex) return this; if (index >= -1) { String text = getText(); if (index == -1) return fromPlainText(text); if (index < text.length() - getEllipsisLength(text)) return fromPlainTextWithIndex(text, index); } throw new IndexOutOfBoundsException(String.valueOf(index)); }