This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
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


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Adding Image, Bolds to JTextPane" Watch "Adding Image, Bolds to JTextPane" New topic
Author

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
expected.
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
method.
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: http://aspose.com/file-tools
 
subject: Adding Image, Bolds to JTextPane
 
Similar Threads
Scaling
JTextPane +insert text,image with style
Images
JTextPane default font
JTextPane and Justified Paragraphs