Solved

Text not getting selected in the JTextArea.

Posted on 2002-03-25
6
258 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
fibonacci ten numbers 4 54
printf performancy 11 86
Java syntax, or is it Selenium 6 42
Cisco ASA: Java web start no go, asdm launcher no go 3 58
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
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…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

733 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