How to mouse click a JTextPane programatically..?

Posted on 2004-08-06
Last Modified: 2011-10-03

I'm trying to set the focus to a JTextPane after another user event occurs (clicking a menu option for example) so that the caret is active in the Pane.

Any help greatly appreciated, thanks...

Question by:sterrius
  • 2
LVL 86

Expert Comment

ID: 11739612
LVL 15

Expert Comment

ID: 11739618
Use a method called requestFocus(); in every event you handle declare it to set the focus to JTextPane.

Example :

JTextPane x = new JTextPane();

Hope that helps . . .
LVL 92

Accepted Solution

objects earned 125 total points
ID: 11741072
LVL 92

Expert Comment

ID: 11937630
requestFocus() is not recomended, from the javadoc:

 "Because the focus behavior of this method is platform-dependent, developers are strongly encouraged to use requestFocusInWindow when possible."

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
wordmultiple challenge 12 116
micro services spring boot application error 3 136
ForLoop Example 3 40
Oracle SQL syntax check  without executing 6 29
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
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 …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

939 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

4 Experts available now in Live!

Get 1:1 Help Now