HTML in a JTextPane

I am displaying simple html in a JTextPane. I've built simple pages with <Input> tags, I load them in the JTextPane and it works - looks great. I can input into these fields, but my question is how can I programmatically get the entry values I've made?

Hi Puce thanks for the comment.
Actually I am never submitting this web pages - I created a component to display web pages and gather the resulting input into a Properties file. The purpose of this is to be able to create sophisticated setup/configuration screens (images, layout, etc) in J2SE using html, so like I said I'm never submitting the pages.
Anyway, I worked out how to do what I needed - I subclassed the HTMLEditorKit and kind of hacked what it's doing. It's pointless, but pretty sweet.

Similar Messages

  • Appending HTML in JEditor/JTextPane (25 dukes)

    HI:
    Is there any way i can append HTML in JEditor/JTextPane,
    as i gets the html data in chunks, so i want to append the html in the existing display in editorpane instead of refreshing it all time, which causes it to flicker,
    Thanks in advance.

    JEditorPane edit = new JEditorPane();
    edit.setEditorKit(new HTMLEditorKit());
    edit.setEditable(true);
    edit.setText("<HTML><b>test<b></HTML>");
    HTMLDocument doc=(HTMLDocument)edit.getDocument();
    try {
    doc.insertString(6,"new text",null);
    catch (Exception ex) {}
    see also other methods of HTMLDocument
    best regards
    Stas

  • How to embed image in html when using JTextPane, HTMLEditorKit, JavaMail

    I am developing a specialized e-mail client that has to be able to send e-mail messages (in html format with images and attachments) that can be read by standard e-mail clients, and receive similar messages from standard e-mail clients.
    I have everything working except for embedding images.
    Images are to appear in the document mixed in with the text, but that's not what I mean by "embed". By "embed" I mean that the image itself is encoded within the html.
    Here's a bit of code to set the context.
    JTextPane bodyPane = new JTextPane();
    bodyPane.setEditorKit(htmlEditorKit);
    bodyPane.setTransferHandler(new DropHandler());
    bodyPane.setDocument(new HTMLDocument());
    In the DropHandler I have the following:
    HTMLDocument htmlDoc = (HTMLDocument) bodyPane.getDocument();
    HTMLEditorKit htmlKit = (HTMLEditorKit) bodyPane.getEditorKit();
    int caretPos = bodyPane.getCaretPosition();
    At this point get "filename", the full path to an image file that has been dropped onto bodyPane.
    String htmlString = "<img src=\"file:///" + filename.replace("\\","/") + "\">";
    htmlKit.insertHTML(htmlDoc, caretPos, htmlString, 0, 0, HTML.Tag.IMG);
    This works just fine. The image is displayed in the document at the point of insertion.
    However, the image itself is an external file. I need to send an e-mail with this image and could send the image file as an attachment, but I obviously can't assume that the recipient of the email is going to save the attachment into the proper location.
    What is the best way to do this?
    There is a technique for embedding the actual image in the html, using this syntax:
    String htmlString = "<a href=\"data:image/png;base64,---mimed png image here--\" alt=\"Red dot\"></a>";
    I can't get this to work in JTextPane, so perhaps it's not supported. Also, there may be limitations on the size of an image. And apparently Internet Explorer doesn't support this.
    From what I read, using a "content identifier", that is, "cid:" and adding the image as another part of the e-mail message is probably the thing to do. I haven't taken the time to explore this yet.
    Does JTextPane support cid? Is that a nonsense question? I suspect what I need to do when the message is being composed is use absolute paths to local files with the images, and then when assembling the e-mail, attach the files and rewrite the html to build in the cid linkage. Similarly, when reading a message with cid's, the thing to do is save the body parts as files and rewrite the cid to point to the actual file.
    I have seen others ask similar questions, one as recently as last December, and the reply was to refer to a Sun tutorial. But that tutorial doesn't address the full problem of 1) inserting an image into a document (instead of attaching an image to a component) and 2) sending it as an e-mail message.
    I have yet to see an example that shows the complete package.
    Am I right that the data option I mentioned is not going to work?
    Am I right that cid is the best approach, and do I understand how to use it?
    Is there something else?
    Thanks
    John

    Hi Rocky,
    Are you using the DC?
    if yes then you need to put the image inside the component folder. after that close the application
    & reopen. You will get the image.
    In case this does not work then try refreshing the portal through server side. Once the cache is cleared, it will be up to view.
    Also check the Activity list you have created. It should be added to the dtr properly or else it wont be reflected once reimported the configurations.
    Regards
    Chander Kararia

  • Custom HTML tags in JTextPane

    Hi all,
    I have seen this topic broached before but, in spite of many hours searching, haven't found the answer I'm looking for...
    I jave a JTextPane containing an HTMLDocument and want to render elements within my own custom tag 'Custom' outlined in red.
    I have subclassed HTMLEditorKit as follows:import javax.swing.text.ViewFactory;
    import javax.swing.text.html.HTMLEditorKit;
    public class HTMLEditorKitForCustom extends HTMLEditorKit{
         public ViewFactory getViewFactory(){
              return htmlFactoryForCustom;
        private static final ViewFactory htmlFactoryForCustom = new HTMLFactoryForCustom();
    }I have subclassed HTMLEditorKit.HTMLFactory as follows:import javax.swing.text.View;
    import javax.swing.text.Element;
    import javax.swing.text.html.HTMLEditorKit;
    import javax.swing.text.StyleConstants;
    public class HTMLFactoryForCustom extends HTMLEditorKit.HTMLFactory{
         public View create(Element element){
              Object object = element.getAttributes().getAttribute(StyleConstants.NameAttribute);
              if(CustomView.CUSTOM_KEY_TAG.equals(object)){
                   return new CustomView(element);
              return super.create(element);
    }And, I have subclassed LabelView as follows:public class CustomView extends LabelView{
         public CustomView(Element element){
              super(element);
         public void paint(Graphics g, Shape a){
              super.paint(g, a);
              Rectangle rectangle = a instanceof Rectangle ? (Rectangle)a : a.getBounds();
              Graphics2D g2d = (Graphics2D)g;
              g.setColor(Color.RED);
              g.drawRect(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
         public static final String CUSTOM_KEY_TAG = "Custom";
         public static final String CUSTOM_TYPE_TAG = "ccVarType";
         public static final String CUSTOM_NUMERIC_TYPE_TAG_VALUE = "Numeric";
    }The JTextPane in question has its EditorKit set to my HTMLEditorKitForCustom throughtextPane.setEditorKit(new HTMLEditorKitForCustom();In combination, these classes ensure that when a <Custom>...</Custom> set of tags is encountered, the text between is rendered with a red outline.
    This works fine when the custom tags and text are inserted but, as soon as a change is made that affects the paragraph containing the custom tags (for example, change alignment, font size, etc.), the content disappears. However, the underlying HTML still shows the <Custom> tag, but with no closing tag and without the text the tags once contained.
    E.g. <Custom>Fred</Custom> becomes simply <Custom>.
    Any help in solving this problem will be greatly appreciated!
    Chris.

    Stas, thanks for your response!
    I did try registering the tag, and associating it with a SpecialAction then with a CharacterAction (I want the user to be able to change the font style, etc. of these Custom items).
    I did this by creating HTMLDocumentForCustom (original name, huh!), subclassing HTMLDocument and inner HTMLReaderForCustom:// (Within HTMLDocumentForCustom)
    public class HTMLReaderForCustom extends HTMLReader{
      public HTMLReaderForCustom(int pos){
        super(pos, 0, 0, null);
        registerTag(new HTML.UnknownTag(CustomView.CUSTOM_KEY_TAG), new SpecialAction());
    }Then I created a new HTMLDocumentForCustom and did textPane.setDocument(document). Now, when I inserted the text between Custom tags, I got this exception:javax.swing.text.BadLocationException: Invalid insert;
         at javax.swing.text.GapContent.insertString(GapContent.java:109);
         at javax.swing.text.AbstractDocument.handleInsertString(AbstractDocument.java:722);I was using the following code to insert the text:SimpleAttributeSet attributes = new SimpleAttributeSet();
    attributes.addAttribute(StyleConstants.NameAttribute, CustomView.CUSTOM_KEY_TAG);
    try{
      document.insertString(1, "Custom Here!", attributes);
    catch(BadLocationException ble){
      ble.printStackTrace();
    }Inserting at position 1 was working fine before trying to subclass HTMLDocument and HTMLReader, and there's already text in the document before trying the insert -- in fact it didn't matter what the insert location was set to, the exception kept occurring.
    Can you see anything obvious I've missed or am I barking totally up the wrong tree?
    Chris.

  • Load HTML in a JTextPane

    Hallo,
    i try to load a simple html file into a JTextPane and then print out this file. I ve noticed, that my last (empty) td-tag-pair disapear. Why this happens? How can i avoid this?
    thanks
    bye
    my html file:
    <html>
      <head>
      </head>
      <body>
        <table border="1" height="200" style="border-style: solid" width="400">
          <tr>
            <td style="border-style: solid">
              1
            </td>
            <td style="border-style: solid">
              2
            </td>
           <td style="border-style: solid">
            </td>
          </tr>
        </table>
      </body>
    </html>and my java programm:
    import java.io.File;
    import javax.swing.JFrame;
    import javax.swing.JTextPane;
    import javax.swing.text.html.HTMLDocument;
    public class HTMLTest {
         public static void main(String[] args) {
              try {
                   JFrame frame = new JFrame();
                   frame.setSize(400,300);
                   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                   JTextPane pane = new JTextPane();
                   HTMLDocument doc = (HTMLDocument) pane.getEditorKitForContentType("text/html").createDefaultDocument();
                   doc.setAsynchronousLoadPriority(-1);
                   pane.setDocument(doc);
                   File f = new File("1.html");
                   pane.setPage(f.toURL());
                   frame.add(pane);
                   frame.setVisible(true);
                   System.out.println(pane.getText());//Here it happens! Where is my last (empty) td-tag-pair?
              } catch (Exception e) {
                   e.printStackTrace();
    }

    Hey,
    It works fine for me.....Ur empty tag is showing up!......and one more suggestion is don't add data directly to JFrame..u have to call...getContentPane()..and add it...may be u have posted that thing wrongly ..anyway i have modified and it's working fine for me!

  • Nested html-tags in JTextPane not possible?

    Hi.
    Why does JTextPane not support contents like this:
    <p align="center">
      <h2>Hello, world!</h2> <!-- nested tag -->
    </p>This code is parsed and changed into:
    <p align="center">
    </p>
    <h2>Hello, world!</h2>Is there any possibility to get around this?
    Cheers,
    kelysar

    I do not know about how to treat HTML by JTextPane.
    According to http://www.w3.org/TR/html4/sgml/dtd.html,
    <!ENTITY % block
    "P | %heading; | %list; | %preformatted; | DL | DIV | NOSCRIPT |
    BLOCKQUOTE | FORM | HR | TABLE | FIELDSET | ADDRESS">
    So you cannot use h2 element in p element.
    Regards,

  • Font color issue with inserted HTML content in JTextPane (HTMLEditor)

    Hi everyone,
    I have a very serious issue with the HTMLEditor I'm developping. This editor is a little bit special since it is intended to edit blocks of HTML content that are loaded when the editor is initialized.
    You can in fact decide to keep this loaded HTML content or start a new HTML document from scratch. Alright, now my issue is the following :
    When text is loaded, it's properly rendered. I have a functionality which let's you see the HTML code from the HTML document used in the editor, so I can check and see if code is correct, and yes, it's correct.
    The problem is that when I try to change the color attribute of some text on my loaded content, nothing happens ! I don't know what's the matter with this bug, I only have it with the color attribute, with every other attribute everything's fine (font, size, etc.)
    The funny thing is that, after I change another attribute for loaded content, like font family, then changing color attribute funcionnality starts to work again !
    I've also noticed that I don't have any of these problems when I start my HTMLDocument from scratch (when I create a new HTML document and start typing text).
    Another weird thing, is that I have a feed-back feature in my editor which reflects attributes for text over which the caret is positionned. For example, if you put caret over red text, the color combo box displays a red value, you know, just like in MS Word. Well, with my loaded content if I have a red text color and I decide to put it in green, the color combo box displays the green value when I click over text for which I have changed color, but in my JTextPane it's still red !! And when I try to see the HTML code generated nothing has changed, everything is still red !
    There is something really strange here, this means that when I get the attributes of the loaded text from the HTMLDocument, color appears to be green, but when it gets rendered in the JTextPane it's still red and when it gets anlyzed to produce the corresponding HTML code, these changed attributes are not taken into account.
    But the most weird thing above all, is that I don't have this bug everytime, sometimes I start my HTML editor applet and it works fine, and some other times this color issue is bakc there. Is this a known bug for Swing API or not ?
    =============
    This is more or less my technique :
    //I declare a global reference to my HTMLDocument
    HTMLDocument _docHTMLDoc;
    //Create a JTextPane
    JTextPane _tpaEditor = new JTextPane( );
    //Set type content to automatically select HTMLEditorKit
    _tpaEditor.setContentType("text/html");
    //Get a referene to its HTMLEditorKit
    HTMLEditorKit _kitHTMLEditor = (HTMLEditorKit) _tpaEditor.getEditorKit( );
    //I then have a function to create new documents
    void newDocument(){
      _docHTMLDoc = (HTMLDocument) _kitHTMLEditor.createDefaultDocument();
      _tpaEditor.setDocument(_docHTMLDoc);
       //I do other stuff wich are not important to be shown here
    //I then have another function to load content
    void loadContent(){
       //I get content from a HashMap I initialized when I started my applet
       String strContent = (String)_mapInitParameters.get("html_content");
       //I set content for my editor
       _tpaEditor.setText(strContent);
    //Notice.. I have tried many other ways to load this text : via HTMLEditorKit and its insertHTML method, I
    //have also tried to store this content in some reader and make HTMLEditorKit read it... and nothing,
    // I always get the bug
    //To change color it goes like this :
    JComboBox _cboColor = new JComboBox();
    //I correctly initialize this combo with colors
    //then I do something like this
    ActionListener _lst = new ActionListener(){
       public void actionPeformed(ActionEvent e){
          Color colSel = (Color) _cboColor.getSelectedItem();
          MutableAttributeSet mas = new SimpleAttributeSet();
          StyleConstants.setForeground(mas,colSel);
          setAttributeSet(mas);
    _cboColor.addActionListener(_lst);
    //Set Attributes goes something like this
    private void setAttributeSet(javax.swing.text.AttributeSet atrAttributeSet) {       
            //Get current 'End' and 'Start' positions
            int intCurrPosStart = _tpaEditor.getSelectionStart();
            int intCurrPosEnd = _tpaEditor.getSelectionEnd();
            if(intCurrPosStart != intCurrPosEnd){
                //Apply attributes to selection
                _docHTMLDoc.setCharacterAttributes(intCurrPosStart,intCurrPosEnd - intCurrPosStart,atrAttributeSet,false);
            else{
                //No selection : apply attributes to further typed text
                MutableAttributeSet atrInputAttributes = _kitHTMLEditor.getInputAttributes();
                atrInputAttributes.addAttributes(atrAttributeSet);

    hi, friend!
    try this:
    void setAttributeToText(JTextPane pane, int start, int end, Color color) {
    MutableAttributeSet new_att = new SimpleAttributeSet();
    StyleConstants.setForeground(new_att,color);
    HTMLDocument doc=(HTMLDocument)pane.getDocument();
    doc.setCharacterAttributes(start,end,new_att,false);
    It works fine in my Application, hope will work in yours, too.
    good luck.

  • Insert HTML table into JTextPane

    hi people!
    I'm inserting htmltable in JTtextPane.
    The problem is, that borders aren't shown.
    they are shown in browser, the code in source view is also valid, but in JTextPane they ar invisible. Can anyone tell me Why?
    Here is a piece of code:
    public class HtmlTable {
    public static String insertTableString(int rows, int columns) {
    String tableString="<TABLE Width=100% Border=1>";
    for (int i=0; i<rows; i++) {
    tableString+="<TR>";
    for (int j=0; j<columns; j++)
    tableString+="<TD> </TD>";
    tableString+="</TR>";
    tableString+="</TABLE>";
    return tableString;
    call of this method:
    HTMLEditorKit kit;
    HTMLDoc=(HTMLDocument)editorTextPane.getStyledDocument();
    kit=(HTMLEditorKit)editorTextPane.getEditorKit();
    kit.insertHTML(HTMLDoc,editorTextPane.getCaretPosition(),HtmlTable.insertTableString(HtmlTable.getRowNumber(), HtmlTable.getColumnNumber()),0,0,HTML.Tag.TABLE);

    no Java code involved, just HTML and CSS
    <HTML>
    <HEAD>
    <style type="text/css">
    td {border-top-width:1pt; border-style:solid; }
    </style>
    </HEAD>
    <BODY>
    <p>
    Your Table goes here
    </p>
    <table>
    <tr>
    <td><p>Row 1 Col 1</p></td>
    <td><p>Row 1 Col 2</p></td>
    </tr>
    <tr>
    <td><p>Row 2 Col 1</p></td>
    <td><p>Row 2 Col 2</p></td>
    </tr>
    </table>
    </BODY>
    </HTML>

  • How to insert row in usercreat table(useing HTML tags)in jtextPane

    hi all
    i creat userdefined table in JTextPane like this
    tableBody.toString() -- iam passeing table tags
    htmlKit.insertHTML(htmlDoc, caretPos, tableBody.toString(), 0, 0, HTML.Tag.TABLE);
    i want to insert a row in table.. i did like this
    htmlKit.insertHTML(htmlDoc, caretPos, sRow.toString(), 0, 0, HTML.Tag.TR); it working..
    but it inserting in current location.. i want to insert ending of table...
    pls help me

    Hi,
    Follow the below logic,
    PROCESS BEFORE OUTPUT.
      MODULE STATUS_0001.
      MODULE POPULATE_TABLE_CONTROL. --> Get the data from table store in 
                                                                          ITAB
      LOOP AT GT_CTRL_LP_D516 INTO GS_WA_CTRL_LP_D516
           WITH CONTROL CTRL_LP_D516
           CURSOR CTRL_LP_D516-CURRENT_LINE.
      The following module moves data to control
        MODULE MOVE_TO_CONTROL.--> Move data from ITAB to table control
      ENDLOOP.
    PROCESS AFTER INPUT.
      LOOP AT GT_CTRL_LP_D516.
      ENDLOOP.
      MODULE EXIT AT EXIT-COMMAND.
      MODULE USER_COMMAND_0001.  --> Here you have to take out the values from table control and update database table
    Reward points if helpful.
    Thanks and regards,
    Mallareddy Rayapureddy,
    Munich, Germany.

  • Extract text file with HTML tags from JTextPane

    hello world
    I have a big problem !
    I am creating an applet with a JTextPane ...
    so I can write text, (bold, italic etc), i can insert images.
    Now i want to create a text file with all the HTML tags
    corresponding to what I wrote in my JTextPane.
    I want to have and save the HTML file corresponding to what i wrote ...
    Is it possible ? Help me please ....
    Jeremie

    writing to a file from an applet is going to take a fair amount of work on your part.
    in order to write to a file from your applet, you have to use servlets or jsp to write to a file on your server. if you wish to write locally, look into signing your applet or policy settings of your browser.
    for writing to a file to the server, i suggest you look into servlets and tomcat to run the servlets.
    i just finished a project that used servlets and they take some time to figure out, but its definitely worth your time.
    here are some websites...
    http://www.j-nine.com/pubs/applet2servlet/Applet2Servlet.html
    http://jakarta.apache.org
    other websites have tutorials that you can look at too
    Andy

  • How Do i get HTML content of JTextPane

    I want formatted text
    i.e < b.>aaaaaaaaaaaaaa< / b >
    I am using it as an Editor.After that i want to save the edited content as formatted text.
    JTextPane.getText()--->Retrun only text -unformatted

    JTextPane.getText()--->Retrun only text -unformattedIt returns the HTML tags for me.
    If you need further help then you need to create a "Short, Self Contained, Compilable and Executable, Example Program (SSCCE)", that demonstrates the incorrect behaviour.
    http://homepage1.nifty.com/algafield/sscce.html
    Don't forget to use the "Code Formatting Tags", so the posted code retains its original formatting.
    http://forum.java.sun.com/help.jspa?sec=formatting

  • HTML encoding with JTextPane

    hello,
    I'm using JTexPane to edit rich text in my application.
    I set the editorkit with
    pane.setEditorKit(new HTMLEditorKit());
    and I create a new document for editing with
    pane.setDocument(pane.getEditorKit().createDefaultDocument());
    but when I enter text in the pane with accent like "j'ai mang� une pomme" , the method pane.getText() return my html document encoded with ISO-10646 aka Unicode where the "�" is &#233;
    I try to create the editorKit for the ContentType "text/html; charset=UTF-8" but it doesn't work.
    How can I change the encoding to UTF-8 ?
    Please help me ...

    hello,
    I know your problem (i'm french), but i don't know how to resolve it easily.
    you can get the HTML code by using
    pane.getText();and change manually characters...

  • Reading HTML in JTextPane

    Can somebody let me know how would I go about reading html with empty spaces into a JTextPane ? Supposing I have text like
    <html><body>     ABCD    EFGH</body></html>When I read the above HTML into the JTextPane(with HTMLEditorKit), it gets rid of all the spaces I put in and considers only one space. Add to that the text is trimmed both ways, so all the spaces I put in at the start of the Document are trimmed.
    Somebody Please ?

    Camickr:
    The pre tag makes a mess of the formatting. Alternatively If I consume the Space Bar and insert '\ 240', I would lose my line wrapping. The line would break in between a word which is scary. The only reason for that is probably the LineBreakMeasurer used by the Editor considers a space and since that space is overwritten by '\ 240' or '& # 160;' , its messed up.
    BBritta:
    Your solution would never work for a JTextPane since the only way I know to put in a space is '\ 240' and not ' ' .
    Thanks Camickr and BBritta. Any other thoughts on this appreciated. I can post in a sample code if required.

  • JTextPane - Parsing HTML

    Hello all,
    I'm working on implementing a Web Browser in Java that recognizes only a small subset of the HTML tags.
    A simplistic way to display a Web Page is to use a JTextPane (JEditorPane) with the setPage(URL) method. The problem here is that setPage() recognizes more tags than I would want him to.
    My first solution was to subclass the ViewFactory class. It worked fine except for tags that are synthesized to HTML.Tag.Content. There are some tags such as <U> (but I can't filter HTML.Tag.Content because I want to accept tags such as <B>).
    Next, I tried subclassing HTMLDocument and its inner class HTMLDocument.HTMLReader. Before going any further, here's the code I use to display HTML in my JTextPane:
    editor = new JTextPane();
    // JScrollPane will contain editor
    JScrollPane scrollPane = new JScrollPane(editor,
    ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
    ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    // init JTextPane
    editor.setEditable(false);
    EditorKit kit = new BasicHTMLEditorKit();
    editor.setEditorKit(kit);
    editor.addHyperlinkListener(...);
    loadPage("http://www.iro.umontreal.ca");
    private void loadPage(String strURL) {
    try {
    loadPage(new URL(strURL));
    } catch (Exception exc) {
    editor.setText("Error: " + exc);
    private void loadPage(URL url) {
    /*Document doc = editor.getDocument();
    EditorKit kit = editor.getEditorKit();
    StringReader reader = new StringReader(HTMLTxt);*/
    try {
    editor.setPage(url);
    //kit.read(reader, doc, 0);
    } catch (Exception exc) {
    editor.setText("Error: " + exc);
    setSubWindowTitle(editor);
    I tried to set the JTextPane document using its constructor:
    new JTextPane(new BasicHTMLDocument());
    And using the setDocument() method.
    I also tried to override the createDefaultDocument of the HTMLEditorKit and return new BasicHTMLDocument().
    In each cases, the parsing works fine because I put some println() in the overriden handleSimpleTag and handleStartTag of my BasicHTMLDocument (note that BasicHTMLDocument extends HTMLDocument and BasicHTMLReader extends HTMLDocument.HTMLReader).
    BUT whenever I try to display the HTML, it does not work. It looks like the parsing tree does not exist anymore (I put some println() in an overriden ViewFactory).
    Could someone help me figuring this out? I'd really like to understand why my strategy does not work. And by the way, is there any other simpler solution ? (note that I am forced to use JTextPane and that I absolutely need to filter undesired tags).
    Thank you all very much. I hope someone will be able to help me! :)

    Bumped. Google and the rest of the internet have been of no help.

  • JTextPane getting html

    hi i am sure that seems as though JTextPane extends JEditorPane it uses html formating.
    is there a way to get the html version of JTextpanes text this is so i can save it and it will still have the same formating???
    can this be done?? if yes can you point me in the right direction.
    thanks
    dave

    or i thought it was!!!!!!!!!!
    it wont let me do that with my code.
    setContentType("text/html");
    /*       Exception in thread "main" java.lang.ClassCastException: javax.swing.text.DefaultStyledDocument
             at javax.swing.text.html.ParagraphView.getStyleSheet(ParagraphView.java:115)
             at javax.swing.text.html.ParagraphView.setPropertiesFromAttributes(ParagraphView.java:83)
             at javax.swing.text.ParagraphView.<init>(ParagraphView.java:40)
             at javax.swing.text.html.ParagraphView.<init>(ParagraphView.java:37)
             at javax.swing.text.html.HTMLEditorKit$HTMLFactory.create(HTMLEditorKit.java:1191)
             at javax.swing.text.CompositeView.loadChildren(CompositeView.java:95)
             at javax.swing.text.CompositeView.setParent(CompositeView.java:122)
             at javax.swing.plaf.basic.BasicTextUI$RootView.setView(BasicTextUI.java:1245)
             at javax.swing.plaf.basic.BasicTextUI.setView(BasicTextUI.java:598)
             at javax.swing.plaf.basic.BasicTextUI.modelChanged(BasicTextUI.java:587)
             at javax.swing.plaf.basic.BasicTextUI$UpdateHandler.propertyChange(BasicTextUI.java:1703)
             at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:333)
             at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:270)
             at java.awt.Component.firePropertyChange(Component.java:7159)
             at javax.swing.text.JTextComponent.setDocument(JTextComponent.java:412)
             at javax.swing.JTextPane.setDocument(JTextPane.java:106)
             at utils.MessageTextPane.<init>(MessageTextPane.java:45)
             at Driver.<init>(Driver.java:58)
             at Driver.main(Driver.java:532)
    */this is the message i get when i run the program with this linesetContentType("text/html"); so there is a problem with the fact that you cant set the syledocument when you are using that formating. can you please help me.

Maybe you are looking for