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 / June 2006

Tip: Looking for answers? Try searching our database.

Showing text cursor in JTextPane

Thread view: 
Jim Rootham - 24 Jun 2006 19:17 GMT
What has to be true for a text cursor to show in a JTextPane?

I have a dynamic set of JTextPanes that may or may not have focus.
Sometimes when they have focus the text cursor does not display.  What
do I need to do to force it to display?

Thanks

Jim Rootham
IchBin - 24 Jun 2006 22:09 GMT
> What has to be true for a text cursor to show in a JTextPane?
>
[quoted text clipped - 5 lines]
>
> Jim Rootham

Do you have text in JTextPanes?

Could the cursor be sitting at the end of the text in the JTextPanes?

If you mean by dynamic that you insert the text then maybe the cursor is
at the end of the inserted text. This would not be visible.

Override DefaultCaret.adjustVisibility() to do nothing.

or

set caret position:  setCaretPosition(int position)

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA http://weconsultants.awardspace.com
__________________________________________________________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor,  Regular Guy (1952-)
Jim Rootham - 25 Jun 2006 03:05 GMT
>> What has to be true for a text cursor to show in a JTextPane?
>>
[quoted text clipped - 18 lines]
>
> set caret position:  setCaretPosition(int position)

Sometimes there is text there, sometimes not.  The cursor will show at
the end of text.  I do want the caret not to show if the JTextPane does
not have focus.

I can't find setCaretPosition as part of JTextPane.

I am calling setSelectionStart and setSelectionEnd when the JTextPane
gets the focus.  I am calling KeyboardFocusManager.clearGlobalFocusOwner
to remove the text cursor after I disable editing when another part of
the panel is sits on is clicked.

Jim Rootham
IchBin - 25 Jun 2006 03:29 GMT
>>> What has to be true for a text cursor to show in a JTextPane?
>>>
[quoted text clipped - 31 lines]
>
> Jim Rootham

You will not find setCaretPosition under JTextPane because it is
inherited from JTextComponent.

setCaretPosition

public void setCaretPosition(int position)

    Sets the position of the text insertion caret for the
TextComponent. Note that the caret tracks change, so this may move if
the underlying text of the component is changed. If the document is
null, does nothing. The position must be between 0 and the length of the
component's text or else an exception is thrown.

    Parameters:
        position - the position
    Throws:
        IllegalArgumentException - if the value supplied for position
is less than zero or greater than the component's text length

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA http://weconsultants.awardspace.com
__________________________________________________________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor,  Regular Guy (1952-)
Jim Rootham - 25 Jun 2006 06:03 GMT
>>>> What has to be true for a text cursor to show in a JTextPane?
>>>>
[quoted text clipped - 51 lines]
>         IllegalArgumentException - if the value supplied for position is
> less than zero or greater than the component's text length

Thanks for the pointer, unfortunately it didn't work.

Would a more careful listing of when the cursor appears and does not
appear help?

Jim Rootham
Jim Rootham - 26 Jun 2006 02:44 GMT
>>>>> What has to be true for a text cursor to show in a JTextPane?
>>>>>
[quoted text clipped - 58 lines]
>
> Jim Rootham

OK, I found it.  Looking at the adjustVisibility documentation gave me
the clue.  You have to call setEditable(true) before the focus gets to
the JtextPane.  In this case it means calling setEditable from
MousePressed as opposed to MouseClicked.

Jim
IchBin - 26 Jun 2006 03:12 GMT
>>>>>> What has to be true for a text cursor to show in a JTextPane?
>>>>>>
[quoted text clipped - 65 lines]
>
> Jim

Cool...

Signature

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
__________________________________________________________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor,  Regular Guy (1952-)



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.