mausam
Posts: 243
Nickname: mausam
Registered: Sep, 2003
|
|
Re: Reading Images from JTextPane
|
Posted: Sep 3, 2003 10:37 PM
|
|
StyledDocument doc = new DefaultStyledDocument();
JTextPane pane = new JTextPane (doc);
Icon icon = new ImageIcon (imagePath);
pane.insertIcon (icon);
//Later while saving the values of the image use.
FileOutputStream fos = new FileOutputStream (fileName);
ObjectOutputStream oos = new ObjectOutputStream (fos);
oos.writeObject (doc); //doc is ur styled document
oos.flush();
oos.close();
// Else use this/
try {
// Get the text pane's document
JTextPane textPane = new JTextPane();
StyledDocument doc = (StyledDocument)textPane.getDocument();
// The image must first be wrapped in a style
Style style = doc.addStyle("StyleName", null);
StyleConstants.setIcon(style, new ImageIcon("imagefile"));
// Insert the image at the end of the text
doc.insertString(doc.getLength(), "ignored text", style);
} catch (BadLocationException e) {
}
//Later read the icon from the StyledDocument.
~Wassalam
|
|