• Post Reply Bookmark Topic Watch Topic
  • New Topic

Why won't this auto text-highlight work?  RSS feed

 
Matt Senecal
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Angela Lamb
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does your GTextArea override the paint method? If so, you will have to add the code for painting highlights to it.
 
Matt Senecal
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Angela Lamb
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!