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 / January 2004

Tip: Looking for answers? Try searching our database.

ImageIcon in JTextPane text?

Thread view: 
Jim Crowell - 13 Jan 2004 20:19 GMT
Hello,

I am writing a method that inputs a 'JTextPane' object with an "Encoded"
text String. So far I have "Decoded" the text and Used the 'JTextPane'
Document Interface and the 'StyleConstants' Class to effect Underline, Font,
Color, etc. on segments of the given text.

My uncertainty is how to replace a text segment that contains a .gif file
name with an ImageIcon.

For example: ".GE </images/geMeatBall.gif> Company." where
</images/geMeatBall.gif> text segment is replaced with the 'ImageIcon'
constructed from the /images/geMeatBall.gif file.

I build the Image Icon OK but if I insert it using the
'JTextPane.insertIcon()' method the image is placed at the beginning of the
'JTextPane' hosted text.

The 'insertIcon' docs say the 'ImageIcon' is inserted into the document as a
replacement for the currently selected content. If there is no selection the
icon is effectively inserted at the current position of the caret.

Looks like I need a way to select the Text Segment programmatically [e.g.
"</images/geMeatBall.gif>" in the above example] before using the
'JTextPane.insertIcon()' Method.

I am at a loss as to how I can do this. Do I somehow use the 'EditorKit' or
some other Class / Interface?

Regards,

Jim
Tanktarta - 13 Jan 2004 23:01 GMT
> Hello,
>
[quoted text clipped - 28 lines]
>
> Jim

All text components have a setCaretPosition(int) that sets the cursor
position and a setSelectedStart() and setSelectionEnd() that you can use
to select the text. Both methods take the index in the document model.

Brett
Andrew Thompson - 14 Jan 2004 03:53 GMT
...
| Looks like I need a way to select the Text Segment programmatically [e.g.
| "</images/geMeatBall.gif>" in the above example] before using the
| 'JTextPane.insertIcon()' Method.

setCaretPosition(), moveCaretPosition().

HTH

--
Andrew Thompson
* http://www.PhySci.org/ PhySci software suite
* http://www.1point1C.org/ 1.1C - Superluminal!
* http://www.AThompson.info/andrew/ personal site
Jim Crowell - 14 Jan 2004 21:51 GMT
Andrew,

That did it.

Many thanks,
Jim...
> ...
> | Looks like I need a way to select the Text Segment
[quoted text clipped - 12 lines]
> * http://www.1point1C.org/ 1.1C - Superluminal!
> * http://www.AThompson.info/andrew/ personal site


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



©2009 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.