-
JTextPane
Hi everyone,
I am trying to insert a image into the jtextpane using the html document as the default document for the jtextpane. It seems that nothing happens when i try to insert the image from disk.
htmldoc - an instance of the HTMLDocument class
TextPane1 - an instance of the JTextPane class
mas - an instance of the MutableAttributeSet class
Here is my code
The file chooser class is ok so i did not include it here
File g = FileChooser3.getSelectedFile();
ImageIcon image1 = new ImageIcon(g.toString());
int w = image1.getIconWidth();
int h = image1.getIconHeight();
mas.addAttribute(StyleConstants.NameAttribute, HTML.Tag.IMG);
mas.addAttribute(HTML.Attribute.SRC, g.toString());
mas.addAttribute(HTML.Attribute.HEIGHT, Integer.toString(h));
mas.addAttribute(HTML.Attribute.WIDTH, Integer.toString(w));
try
{
int p = TextPane1.getCaretPosition();
htmldoc.insertString(p, " ", mas);
}
catch(Exception e)
{
}
The above code compiles without errors but does not seem to work.
Can someone tell me how to insert an image into a html document in the jtextpane or show me an example of inserting icons in a html document
Thank You
Yours Sincerely
Richard West
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks