Solved

Text not getting selected in the JTextArea.

Posted on 2002-03-25
6
253 Views
Last Modified: 2010-03-31
I am creating a editor using SwingI. My UI contains JTextFields, JTextArea , JTree and some buttons.
I am providing the functionality of searching and selecting any character/string from the JTextArea. Flow is like
user clicks on a button, a dialog appears wherein he can enter the string to be searched in the JtextArea, if that string
is present than it gets selected in the TextArea.

Problem is if i first click on JTextArea and than on the search button in the dialog than my string
is getting selected in the TextArea but if i select any other component like textField or tree and than click
on search button in the dialog than the string in the textarea is not getting selected. However when i printed the selected
text of the textarea it printed it correctly but still the text is not getting selected in the textarea.

I have tried with both textArea.requestFocus()  and textArea.grabFocus() and also used setCaretPosition. but nothing worked. I am selecting text like textArea.select( int,int ).

Any help will be welcome.

Thanks in advance.
0
Comment
Question by:ugarg
6 Comments
 
LVL 92

Expert Comment

by:objects
ID: 6895239
Try making the caret selection visible before calling select:

textArea.getCaret().setSelectionVisible(true);
0
 
LVL 9

Expert Comment

by:Ovi
ID: 6896008
perhaps a dummy response but you could try to set the location of your search dialog relative to the text area container component. So if you have the text area embed in a JPanel set the location of the search dialog relative to that JPanel like setLocation(containerPanel.getLocationOnScreen());

Why I post that ? I've implemented sometime ago a incremental search plug-in to a JTextPane, and I was displaying the dialog outside the application. The results was the same as in your case, until I've "discovered this strange thing". It could work or not, give'it a try.


About using area.requestFocus() did you use that just before selecting the text or in other place (order) ?
0
 

Author Comment

by:ugarg
ID: 6898218
RquestFocus i tried using boith before and after. I will give a try with whatever u had suggested. But making caret visisble is working .
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 1

Expert Comment

by:Moondancer
ID: 6961493
ADMINISTRATION WILL BE CONTACTING YOU SHORTLY.  Moderators Computer101 or Netminder will return to finalize these if they are still open in 14 days.  Experts, please post closing recommendations before that time.

Below are your open questions as of today.  Questions which have been inactive for 21 days or longer are considered to be abandoned and for those, your options are:
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you, but may help others. You must tell the participants why you wish to do this, and allow for Expert response.  This choice will include a refund to you, and will move this question to our PAQ (Previously Asked Question) database.  If you found information outside this question thread, please add it.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question (if it has no potential value for others).
   --> Post comments for expert of your intention to delete and why
   --> YOU CANNOT DELETE A QUESTION with comments; special handling by a Moderator is required.

For special handling needs, please post a zero point question in the link below and include the URL (question QID/link) that it regards with details.
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
Please click this link for Help Desk, Guidelines/Member Agreement and the Question/Answer process.  http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp

Click you Member Profile to view your question history and please keep them updated. If you are a KnowledgePro user, use the Power Search option to find them.  

Questions which are LOCKED with a Proposed Answer but do not help you, should be rejected with comments added.  When you grade the question less than an A, please comment as to why.  This helps all involved, as well as others who may access this item in the future.  PLEASE DO NOT AWARD POINTS TO ME.

To view your open questions, please click the following link(s) and keep them all current with updates.
http://www.experts-exchange.com/questions/Q.20260149.html
http://www.experts-exchange.com/questions/Q.20260294.html
http://www.experts-exchange.com/questions/Q.20274743.html
http://www.experts-exchange.com/questions/Q.20274749.html
http://www.experts-exchange.com/questions/Q.20281226.html
http://www.experts-exchange.com/questions/Q.20282947.html



*****  E X P E R T S    P L E A S E  ******  Leave your closing recommendations if this item.  If you are interested in the cleanup effort, please click this link http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20274643
POINTS FOR EXPERTS awaiting comments are listed here -> http://www.experts-exchange.com/commspt/Q.20277028.html
 
Moderators will finalize this question if in @14 days Asker has not responded.  This will be moved to the PAQ (Previously Asked Questions) at zero points, deleted or awarded.
 
Thanks everyone.
Moondancer
Moderator @ Experts Exchange
0
 
LVL 92

Accepted Solution

by:
objects earned 75 total points
ID: 7234680
> But making caret visisble is working .

Then accept my answer :-)
0
 

Expert Comment

by:SpideyMod
ID: 8289938
Force Accepted

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This video teaches viewers about errors in exception handling.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now