int () { JTextComponent textComponent = getTextComponent(); final int caretPosition = textComponent.getCaretPosition(); final int start = textComponent.getSelectionStart(); final int end = textComponent.getSelectionEnd(); return caretPosition == start ? end : start; }