• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

TextField & TextArea problem

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am working on program that uses a text box to intally show text and another text box that allows the user to enter in the same text. Now if the user enters in somthing different in the input text box to the first text box the progran flags this as an error. This program in a nutshell is a 'Typing Teacher' program.
THE PROBLEM:
The problem is how do I show this error. What I want the text box to do is set the background colour to red BUT ONLY ON THE MISPELT WORD and not the entire text box.I know the alogorithim to do this its just making the text box highlight one word. I would be so, so grateful if some one could shed some light on this problem.
many thanx...
 
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are three methods that you'll need to use:
setSelectionStart()
setSelectionEnd()
setSelectionColor()
If you know where the word is in the string of text (and I understand from your post that you do), just set the selection start so that it's just before the word, and the selection end so that it's just after the word. Set the color you want the selection to be (this only needs to be done once for the whole JTextArea/Field), and you're good! .

Originally posted by John Howard:
I am working on program that uses a text box to intally show text and another text box that allows the user to enter in the same text. Now if the user enters in somthing different in the input text box to the first text box the progran flags this as an error. This program in a nutshell is a 'Typing Teacher' program.
THE PROBLEM:
The problem is how do I show this error. What I want the text box to do is set the background colour to red BUT ONLY ON THE MISPELT WORD and not the entire text box.I know the alogorithim to do this its just making the text box highlight one word. I would be so, so grateful if some one could shed some light on this problem.
many thanx...


 
A magnificient life is loaded with tough challenges. En garde tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic