File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Adding Image, Bolds to JTextPane Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Adding Image, Bolds to JTextPane" Watch "Adding Image, Bolds to JTextPane" New topic

Adding Image, Bolds to JTextPane

Scott Florez
Ranch Hand

Joined: Dec 05, 2006
Posts: 58
Hi. I'm using the code below to generate a JTextPane. However, the image is not being displayed at the top of the pane. I'm trying to read the image from the current working directory (not a URL). I've tried every possible path I can think of. I'm not getting any errors when I try to read the image; it just doesn't show up. The bolds also aren't showing up as bold. Can anyone help? Thanks!

[ March 01, 2007: Message edited by: Scott Florez ]
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
I tried your code and it worked okay. Both the image and the bold text appeared as
About image loading, the getResource methods search the class path for the image. If the
File(path) cannot be found you would likely get a message from your createImageIcon
However, if ImageIcon cannot decipher the file or load the data it says nothing. You have
to ask it how the loading went. Here's an idea for the asking part:

That the bold text did not appear suggests something else. You can get the StyledDocument
from the JTextPane and query it for the Styles it contains. Write out the attributes to
see if they match what you put in.
I agree. Here's the link:
subject: Adding Image, Bolds to JTextPane
It's not a secret anymore!