Solved

Text not getting selected in the JTextArea.

Posted on 2002-03-25
6
256 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Java Timer (static) 9 43
eclipse shortcuts 9 54
difference of if loops 23 49
tomcat not starting 6 45
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
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…

776 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