News:

Holy shit, it's 2018 2019 2020 2021 2022 2023 2024, and the US isn't a fascist country! What a time to be alive.

Main Menu

[Java] Modifying a JTextArea causes the field to 'select all'

Started by Camel, December 27, 2007, 02:15:04 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Camel

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.

<Camel> i said what what
<Blaze> in the butt
<Camel> you want to do it in my butt?
<Blaze> in my butt
<Camel> let's do it in the butt
<Blaze> Okay!