Solved

Text not getting selected in the JTextArea.

Posted on 2002-03-25
6
254 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
network + 7 80
Java asynchronous logging 4 50
servlet doXXX methods 3 38
How  Can  I  resolve   this  Error "java.sql.SQLException: Invalid column index" 4 25
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

896 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

15 Experts available now in Live!

Get 1:1 Help Now