Forums Register Login

Why won't this auto text-highlight work?

+Pie Number of slices to send: Send
Hello! Maybe someone can help me out with this one.
I have a GTextArea (extends JTextArea) that some text is typed into. I have created a search/replace method that searches the text and puts results into a JTable. When a user double clicks on a result in the table, the text in the GTextArea (corresponding to the "find" in the table) is supposed to be highlighted. But that's not happening.
The included method is triggered by a mouse event (double-click with button 1) on a row in a JTable. It pulls a row (Vector) from a TableModel and pulls a GTextArea from that vector. Then a range of text from that GTextArea is explicitly selected, using setSelectionStart()/End().
The text range is successfully selected (verified by doing a replace on the selected range), but no highlighting takes place. Is there something I'm missing?
+Pie Number of slices to send: Send
Does your GTextArea override the paint method? If so, you will have to add the code for painting highlights to it.
+Pie Number of slices to send: Send
I just checked, and it doesn't override the paint method. Could the document attached to the GTextArea have something to do with it?

Originally posted by Angela Ann:
Does your GTextArea override the paint method? If so, you will have to add the code for painting highlights to it.


+Pie Number of slices to send: Send
I don't think it would have anything to do with the document. The problem may be with the last line of the method, where you set selectedArea to textArea. Is there some reason why you can't just set the selection directly on selectedArea? Also, make sure that you are not setting the caret position of the text area elsewhere in the code, since that will automatically turn off what you just highlighted.
I can't beleive you just said that. Now I need to calm down with this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 861 times.
Similar Threads
Buggy text highlighting.
Row Selection problems with JTable
JTable
Dynamic JTable
JTable
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 04:30:04.