• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with select(int start, int end) method of TextArea  RSS feed

 
Gaurav Chauhan
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ranchers,

I am stuck in a problem while using the select method of TextArea class. Here is my code:





The select(int , int ) method inside the MyText() constructor is perfectly working but when i am using the same inside the find() method it is not selecting the text............

Anyone please help me on this.
[ September 14, 2008: Message edited by: Gaurav Chauhan ]
 
Gaurav Chauhan
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bounce............

No Replies yet
 
Campbell Ritchie
Sheriff
Posts: 55351
157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Gaurav Chauhan:
Bounce............

No Replies yet
Please look at this FAQ.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> when i am using the same inside the find() method it is not selecting the text............

actually, it is.

you don't see it because you have transfered focus from the textArea to the button
(just by clicking the button)

run the code again.
after clicking the button, press the tab key and the selection should be highlighted.

simple fix is to add this line
bFind.setFocusable(false);

(and there is a way you can have the selection highlighted without the need to have focus)
 
Gaurav Chauhan
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is my original code. I am supposed to build a find and replace box. This is what i did.....



Kindly run the code and you will find the issue that i am facing..........
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you're not trying too hard.

the first example I explained how the focus was the issue,
between the textArea and the button.

now you post code that contains a couple of textfields, and presumably,
your problem happens when you follow these steps
type something into the textArea
type something into the find textfield
(possibly) type something into the replace textfield
click the find button

now the textArea doesn't show the selection - is that the problem?

if so, where is the focus now?
not the button - that was a fix for the first posted code.
could the focus be with the last textfield that something was typed into?

anyway, look up the apidocs for
textArea.requestFocusInWindow();
 
Gaurav Chauhan
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot mate.

I understood it. TextArea lost it's focus so the highligted text was not shown.

I used the requestFocusInWindow() as per your suggestion and it's working :-)
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!