Text not getting selected in the JTextArea.
Posted on 2002-03-25
I am creating a editor using SwingI. My UI contains JTextFields, JTextArea , JTree and some buttons.
I am providing the functionality of searching and selecting any character/string from the JTextArea. Flow is like
user clicks on a button, a dialog appears wherein he can enter the string to be searched in the JtextArea, if that string
is present than it gets selected in the TextArea.
Problem is if i first click on JTextArea and than on the search button in the dialog than my string
is getting selected in the TextArea but if i select any other component like textField or tree and than click
on search button in the dialog than the string in the textarea is not getting selected. However when i printed the selected
text of the textarea it printed it correctly but still the text is not getting selected in the textarea.
I have tried with both textArea.requestFocus() and textArea.grabFocus() and also used setCaretPosition. but nothing worked. I am selecting text like textArea.select( int,int ).
Any help will be welcome.
Thanks in advance.