How the heck do i display an image in jeditorpane?

Ive search the site and i still cant find any info on how to enter an image into jeditorpane, i know its possible cause i can display web pages in it without a hitchcheers-
[193 byte] By [michaelodeon] at [2007-9-26 4:48:13]
# 1
See http://developer.java.sun.com/developer/codesamples/examplets/javax.swing.text/232.html
earljavadev at 2007-6-29 18:38:24 > top of Java-index,Archived Forums,Swing...
# 2
That just confused me...where am i?
michaelodeon at 2007-6-29 18:38:24 > top of Java-index,Archived Forums,Swing...
# 3
In their code, doc means the Document of the JEditorPane. Make sure you include the necessary import statements too (ImageIcon, etc).Document doc = myJEditorPane.getDocument(); // continue with their try-catch code
earljavadev at 2007-6-29 18:38:24 > top of Java-index,Archived Forums,Swing...
# 4
is there any documentation on this, i cant really follow it from this snippet.cheers-
michaelodeon at 2007-6-29 18:38:24 > top of Java-index,Archived Forums,Swing...
# 5

earljavadev's answer was pretty straightforward.

it's only one way to do it, but just follow his directions to get the code at the bottom. there are other insert*** methods that you can call to get content into the document as well.

// *** code folows ***

Document doc = myJEditorPane.getDocument();

String imageFile = "myImage.png"; // get the image from a filechooser if you want

Style style = doc.addStyle("StyleName", null); // ignored

StyleConstants.setIcon(style, new ImageIcon(imageFile));

try

{

doc.insertString(doc.getLength(),

"ignored text", style);

}

catch (BadLocationException ble)

{

System.err.println("BadLocationException: " + ble);

}

HeinerJ at 2007-6-29 18:38:24 > top of Java-index,Archived Forums,Swing...
# 6
thanx guys
michaelodeon at 2007-6-29 18:38:24 > top of Java-index,Archived Forums,Swing...
# 7
not to be a pest or anything, but Document doesnt seem to have a method addStyle(); is it StyledDocument or something like that P.S. Styled document doesnt work-thanks for your replys so far
michaelodeon at 2007-6-29 18:38:24 > top of Java-index,Archived Forums,Swing...
# 8

Well, it's been a long time any you probably have the answer, but in case others are looking

(like I was), you need to use the correct "StyleName" which is "icon", in other words, replace

the String "StyleName" with the String "icon" and it will work. See http://java.sun.com/docs/books/tutorial/uiswing/components/simpletext.html

for a real example.

Asbel at 2007-6-29 18:38:24 > top of Java-index,Archived Forums,Swing...