I've got a tab-completion system where, when the user presses tab, a list pops up in a dialog below the chat window with all of the users that match the search pattern. When the user selects a user from the list, the contents of the box change to "[username]: {cursor}" if there are no spaces prefixing the tab completion string, or to "[prefix] [username] {cursor}[suffix]" otherwise.
private void tcSelect(String selection) {
if((tcBefore.length() == 0) && (tcAfter.length() == 0)) {
chatTextArea.setText(selection + ": ");
chatTextArea.setCaretPosition(chatTextArea.getText().length());
} else {
chatTextArea.setText(tcBefore + selection + tcAfter);
chatTextArea.setCaretPosition(tcBefore.length() + selection.length());
}
// Exit TC mode
tcPopupWindow.setVisible(tabComplete = false);
}
When using certain look and feels, this results in the entire entire text area being selected. The affected Look and Feels vary based on OS, but Windows seems to be affected by most of them.