Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / March 2004

Tip: Looking for answers? Try searching our database.

Setting caretPosition correctly

Thread view: 
VI - 16 Mar 2004 16:52 GMT
Hi

I want to set the CaretPosition right where the component (JButton) is
in JTextPane (textPane).

I have used the following code, which is supposed to work:

    textPane.setCaretPosition(textPane.viewToModel(e.getPoint()));

... in showPopup(MouseEvent e) which is called when I right-click on the
button.

I want the cursor to move there. However, it only works when the button
is on the first line - even this fails sometimes - and never works when
it's elsewhere (anywhere below).

Has anyone had the same problem and/or found a solution to this?

Thanks

VI
Christian Kaufhold - 17 Mar 2004 23:59 GMT
Hello!

> I want to set the CaretPosition right where the component (JButton) is
> in JTextPane (textPane).
[quoted text clipped - 9 lines]
> is on the first line - even this fails sometimes - and never works when
> it's elsewhere (anywhere below).

MouseEvent points are in the coordinate system of their component.

Use SwingUtilities.convertPoint to convert from JButton to JTextPane
coordinate system.

Christian
Signature

The cat in the hat came back, wrecked a lot of havoc on the way
Always had a smile and a reason to pretend

                                R.E.M., The Sidewinder Sleeps Tonight

VI - 19 Mar 2004 15:55 GMT
> Hello!
>
[quoted text clipped - 18 lines]
>
> Christian

After making the mentioned change and an amendment to the above code I
got what I required.

Thanks a lot for your help. You really are a Swing expert!

Regards

VI


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.