Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Buggy text highlighting.  RSS feed

 
Matt Senecal
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anyone have any idea why the following bit of code will change the highlight color of the JTextArea, but won't actually do the highlighting I tell it to?
 
Angela Lamb
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this instead:
textArea.setCaretPosition(selStart.intValue());
textArea.moveCaretPosition(selEnd.intValue());
I think the setSelectionStart and setSelectionEnd methods will only work if there is already some text selected.
 
Mark Spritzler
ranger
Sheriff
Posts: 17309
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is wierd because I know that we got it to work on our program a while back. and here is the code that we used.

As you notice we didn't use anything to "select" the text, and I couldn't find it in any of our code, but I know it had worked. Try it and see if it highlights and select all the text in the JTextBox. If not I'll look again for any code that might suggest that.
Mark
p.s. What are you converting? What was the old system written in? Ours was Foxpro 2.6
 
Matt Senecal
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the suggestion and code. I'll give it a whirl on Monday morning.

p.s. What are you converting? What was the old system written in? Ours was Foxpro 2.6

I'm actually not doing a conversion, although from the code snippit I posted it must seem that way. I'm just trying to add text highlighting to a prviously written Java module that does data retrieval.
[ May 17, 2002: Message edited by: Matt Senecal ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!