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