• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Buggy text highlighting.

 
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?
 
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.
 
ranger
Posts: 17344
11
Mac IntelliJ IDE 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 ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!