• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Why won't this auto text-highlight work?

 
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic