dcsimg
Each click of the same button selects(highlights)the next instance of a word in a textArea. The searched word comes from a textField...
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Jill_Jones
Posted On:   Tuesday, April 9, 2002 12:15 AM

Creating a frame with a JTextArea in a JScrollPanel and a JButton and JTextField in another panel. The user enters text into the textArea, then enters a word in the textField (word)and pushes the button (it's a Find button.) The button click should find the first instance of word in the textArea. I've got this. The problem is that a second button click should find the next instance of the word, etc. until the end of text in the textArea is reached. At this point a label ("End of text") should appear next to the textField. I think the problem is that it is necessary to use textArea.requestFocus() in order to successfully select (highlight) the text. I use requestFocus in the listener for the button so each cli   More>>


Creating a frame with a JTextArea in a JScrollPanel and a JButton and JTextField in another panel. The user enters text into the textArea, then enters a word in the textField (word)and pushes the button (it's a Find button.)


The button click should find the first instance of word in the textArea. I've got this. The problem is that a second button click should find the next instance of the word, etc. until the end of text in the textArea is reached. At this point a label ("End of text") should appear next to the textField.


I think the problem is that it is necessary to use textArea.requestFocus() in order to successfully select (highlight) the text. I use requestFocus in the listener for the button so each click calls the method and starts at the beginning of the text. Can someone give me a clue, please?

   <<Less
About | Sitemap | Contact