The Artima Developer Community
Sponsored Link

Java Answers Forum
Reading Images from JTextPane

1 reply on 1 page. Most recent reply: Sep 3, 2003 10:37 PM by mausam

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
sabab

Posts: 34
Nickname: sabab
Registered: Aug, 2003

Reading Images from JTextPane Posted: Sep 3, 2003 10:49 AM
Reply to this message Reply
Advertisement
Dear All

In my project, i am having a JTextPane and in this JTextPane i am adding Images(Different GIF images).
when i am reading the values in this JTextPane(For storing in the database) using getText() method i am getting only text values, in place of images i am getting blank space .I want to read the images also OR i want some mechanism to represent these images and text so that i can store these data in a database table for future reference

pls help me


mausam

Posts: 243
Nickname: mausam
Registered: Sep, 2003

Re: Reading Images from JTextPane Posted: Sep 3, 2003 10:37 PM
Reply to this message Reply
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

Flat View: This topic has 1 reply on 1 page
Topic: Response wrapper problem ?!! Previous Topic   Next Topic Topic: How to pass byte[] from one servlet to another, which are on diff servers?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use