Unable to save JTextPane content

Hello,
I'm having a problem to save the content of a JTextPane with HTMLEDitorKit. ( With RTF it works fine).
Everytime I'm trying to save what I have typed into the panel, the file h&as only the folllowing tags.
<html>
  <head>
  </head>
  <body>
    <p style="margin-top: 0">
    </p>
  </body>
</html>I do not undrstand how all this works and how to do. Thanks in advance for any idea.
Gege
Here is just a sample,code
package test;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.OutputStream;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.text.JTextComponent;
import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.HTMLEditorKit;
import javax.swing.text.html.parser.ParserDelegator;
public class SaveHTML
  public static void main(String args[]) {
  JFrame frame = new JFrame("Saving Sample");
   Container content = frame.getContentPane();
    final JEditorPane editorPane = new JEditorPane();
    editorPane.setEditable(true);
    JScrollPane scrollPane = new JScrollPane(editorPane);
    content.add(scrollPane, BorderLayout.CENTER);
    editorPane.setEditorKit(new HTMLEditorKit());
    JPanel panel = new JPanel();
    // Setup actions 
    Action saveAction = new AbstractAction() {
          private static final long serialVersionUID = 1L;
          { putValue(Action.NAME, "Save");}
      public void actionPerformed(ActionEvent e) {
        doSaveCommand(editorPane, filename);
    JButton saveButton = new JButton(saveAction);
     panel.add(saveButton);
     content.add(panel, BorderLayout.SOUTH);
      frame.setSize(250, 150);
     frame.setVisible(true);
public static void doSaveCommand(JTextComponent textComponent,  String filename)
   try
           OutputStream writer = new ByteArrayOutputStream();
             HTMLEditorKit htmlKit = new HTMLEditorKit();
           HTMLDocument htmlDoc = (HTMLDocument) htmlKit.createDefaultDocument();
           int le = htmlDoc.getLength();
             OutputStream out2 = new FileOutputStream(new File("filename.htm"));
             htmlKit.write(out2, htmlDoc, 0, le);
             out2.close();
             System.out.println("Saved");
  catch (Exception ex) { ex.printStackTrace(); } 
}

Thanks both of you for your reply. As suggested by fgb, I use the component.getDocument() , and it works fine.
I haven't tested yet component.write. I'll try later to see the difference.
Now I need to see whether I can re reload it into an empty JTextPane. I have found an example on the web, I'm going to try it.
Many thanks again.

Similar Messages

  • How to save  JTextPane contents to a file ?

    Hello,
    I'd like to save the content of a JTextPane document into a buffer then to save it into a Database Column (I'm using MYSQL).
    If I'm using the getText() method, all attributes (color, font, and so forth) are lost
    I have also tried to use the write(Writer) method into a ByteOutputStream, but here again, attributes are lost.
    Thanks to anyone who may provide me with an example.
    Gege

    While the RTFEditorKit allows you to save files all with the same styling, the HTMLDocument class (if set as your JTextPane's StyledDocument) and HTMLEditorKit (works for both default StyledDocuments (on a more limited basis, I believe) and HTMLDocument's) allow you to save heterogeneous styling. However, it does NOT support the StyleConstants.ComponentAttribute, and does not provide a satisfactory exception when you attempt to use them (at least last time I checked - attempting to insert a component into an HTMLDocument yielded a NullPointerException, which wasn't useful at the time, but now that Java's gone open source or whatever, it's much more useful...).
    So anyway, the point is, you can probably just use your regular old JTextPane combined with HTMLEditorKit.write() and HTMLEditorKit.read() methods. You will need to translate components into some sort of text (if they're Serializable, just write them to a ByteArrayOutputStream and convert it into a String, add some custom escape-char-like magic, and you're there) before using the write method (and of course, translating it back after you read it in).
    Hope this helps.

  • Unable to save Interactive form content

    Hello Experts,
      Can someone tell me how can I save the contents of my pdf locally ? I am only able to save a blank form but not the information that i have filled in. Have experimented with the various possible modes but so far no success. Thank you.
    from
    Kwok Wei

    Hi Kwok,
    If you create an XDP with the Designer and save it as PDF form, the PDF will not contain the proper right for saving it.
    But if you create an Interactive Form UI in a WD project in the Developer Studio and design your form from Dev Studio, then when the WD application runs, the XDP is tried to sent to the preconfigured ADS (a web service responsible for PDF generation).  If the ADS is configured well and contains the <b>proper credential file</b> for operations such as save, the returning PDF displayed in the browser will contain the right for saving and you can save it locally. From this time the local PDF can be open with Reader and the Reader will always give the possibility for saving.
    Do you need only the contents ? Then you can also try the followings:
    1. Save as text... command from the Reader
    2. If you like PS much more then a readable text file, you can also choose Print.. and click on the Print to file checkbox.  (of course this solution rather a joke than a suggestion)
    Regards,
    Ferenc

  • Unable to save a 'smallest size file' pdf from illustrator 5.5

    We recently insalled Adobe Standard 5.5
    I often save PDF files from Illustrator using the built in PDF options available from the PDF drop down menu bar when saving files. Usually I will save a visual as a 'smallest file size' or make use of the 'high quality print' option for other files etc.
    Why cant I do this on CS5.5?
    In addition, the colour is not acurate at all!
    Please help

    Hi Scott - I found the following thread on the net. So I had a look on my time machine back-ups and copied the files from there, which I then pasted into my Settings folder as you suggested.
    Ta da!! All working again!
    Any idea how I could restore these settings from a backup?
    Thanks!
    The PDF presets reside in Root/Library/Application Support/Adobe/Adobe PDF/Settings/
    After I had installed 10.6.5, 6 preset files were removed from the Settings folder. The folder tree itself remained, it was just that some of the contents of "Settings" were deleted. I have fixed the problem by copying the deleted settings files from a backup.
    These are the files which were deleted:
    Smallest File Size.joboptions
    Press Quality.joboptions
    PDFX4 2008.joboptions
    PDFX3 2002.joboptions
    PDFX1 2001.joboptions
    High Quality Print.joboptions
    These files were not deleted:
    Standard.joboptions
    PDFA1b 2005 RGB.joboptions
    PDFA1b 2005 CMYK.joboptions
    Oversized Pages.joboptions
    Somebody at Adobe community support for Indesign directed me to restore these files from a backup, which solved the problem.
    Re: Unable to save a 'smallest size file' pdf from illustrator 5.5 

  • The server was unable to save the form at this time. Please try again - tried the trust standards...

    2013 standard sharepoint server.  Content DBs were on a Trial enterprise server and copied over to standard server. All was good on trial server.
    there are 8 sites on server, 2 of the sites cannot create or edit items, they get "The server was unable to save the form at this time. Please try again"
    googling around i tried everything. restarted search host controller, checked ram usage (8gb free), manage content types, iisresets, edit the web.config file ( add things for ram, search host, etc), no alternate access mappings, .net HTTP activation, rebooted
    server... I'm sure i missed some.
    The server is new install, all but the August HF CUs. Trial server the content DBs came from is at same level.
    It is not a server level issue as the other 6 sites are fine. its something with just 2 sites.
    kinda stuck here...
    Thanks,
       Scott<-

    With the USL Logs were hard to track down what was happening, though I think it was too do with /_vti_bin/client.svc/ProcessQuery.
    I did the Enable/Disable Anonymous Access on the Directory with no luck.
    Brought up Fiddler and Saw that I was getting 401 and 500 Errors on
    GET http://team.intranet.eandm.com/it/_vti_bin/client.svc/ProcessQuery HTTP/1.1
    So it had something to do with Permissions. I checked the Authentication and the sites that worked had Forms Auth Enabled, and the ones that didn't, didn't have forms Auth enabled.  Enabling it manually was no go.
    I then went though the web.config on the working and non-working sites and there were some differences.   The Authentication was Forms on the working site, Windows on the nonworking. There was many things not present. httpModules section was missing,
    Many of the Microsoft Identity /Authentication lines etc. 
    So I Basically took the web.config from the working site and copied it to the non-working site preserving the following line from the original web.config:
    <machineKey validationKey="{key}" decryptionKey="{key}" validation="{hash}" />
    After that I had Security Issues, Though I think this was Caused by the July 2014 CU making everything use the Microsoft Identity parts, where as the server I was porting form had the sites created before the July 2014 CU. (though both were at the same level)
    Even though all of the users were present in the site security, I had to Drop and re-add them to every site/and list with special Perms. 
    With the Security Fixed, I no longer received the Error "The server was unable to save the form at this time. Please try again"
    Knock on wood its all functioning fine. 

  • Oracle SQL Developer 1.5.5 Unable to save file

    I edit content of a column in a table I get this when trying to save change:
    Unable to save TABLE ... ("Failed to save changes").
    This error disappear when I do the same task in Oracle SQL Developer 1.1.3.
    Please help me!

    when I run:
    UPDATE "OWNFTS"."BONGDATHAMSO"
    SET LTDKQURL = 'http://soccernet.espn.go.com/fixtures?league=ita.1&cc=4716'
    WHERE ROWID = 'AAASBeAAGAAAAEgAAH' AND ORA_ROWSCN = '4238785';
    commit;
    from SQL Worksheet, there's "Enter Substitution Variable" window inform me to enter something in a textbox beside "CC:" label.
    Clicking "OK" or "Cancel" on this window with or without filling textbox has the same result:
    +0 rows updated+
    commit succeeded.
    AND the command which was cutting ORA_ROWSCN predicate:
    UPDATE "OWNFTS"."BONGDATHAMSO"
    SET LTDKQURL = 'http://soccernet.espn.go.com/fixtures?league=ita.1&cc=4716'
    WHERE ROWID = 'AAASBeAAGAAAAEgAAH';
    commit;
    fired the same " window
    but:
    +1 rows updated+
    +commit succeeded.+
    AND after refresh Table, I couldn't see the new value.
    Edited by: user11193632 on Aug 5, 2009 7:30 PM

  • Unable to scroll iframe content in Safari on ipad

    unable to scroll iframe content in Safari on ipad

    Try going to https://appleid.apple.com, click Manage my Apple ID and sign in with your current iCloud ID.  Click edit next to the primary email account, change it back to your old email address and save the change.  Then edit the name of the account to change it back to your old email address.  You can now use your current password to turn off Find My iDevice, even though it prompts you for the password for your old account ID. Then save any photo stream photos that you wish to keep to your camera roll.  When finished go to Settings>iCloud, tap Delete Account and choose Delete from My iDevice when prompted (your iCloud data will still be in iCloud).  Next, go back to https://appleid.apple.com and change your primary email address and iCloud ID name back to the way it was.  Now you can go to Settings>iCloud and sign in with your current iCloud ID and password.

  • Unable to save a pages file

    Creating a 10 page newsletter in Pages 09. Unable to save the file even though it has previously been saved on the same computer. Unable save, save as, or email the file. Any suggestions?

    Hello
    It would be fine to get the exact message which you get.
    An odd behavior was described several times : the system refuse to save the doc even when the user try to export it.
    If like me you have two versions installed : one running in French and one running in English, you may try to copy from one version to the other one. It's the unique way giving a chance to keep everything.
    The problem with this behavior is that, as we can't save, there is no way to study the file's content to check if there is something corrupted in it.
    It's a really annoying f
    "feature" because it will be very difficult to understand what fails and so build a way to get rid of it.
    At this time, the best workaround is to use an autosave tool creating incremental backups.
    Yvan KOENIG (VALLAURIS, France) samedi 13 novembre 2010 09:19:09

  • Unable to save as a variant

    Hi all,
    I am unable to save avariant for the T-code VA05 (List of sales orders).
    To be more descriptive, I use the t-code VA05 to list the sales orders of the particular customer.
    The list will get displayed then I will do some changes in the lay out and will save as a variant.
    So that next time I can directly call up this variant instead of do the chnges again.
    How can I do this.
    Regards,
    Mallesh

    Hi
    You can use T.Code SHD0 ,Here enter your transaction code
    Enter transaction variant name  as per nomenclature policy.
    Select Create transaction variant .
    You will get first screen of VA05 ,enter relevant data.
    enter
    you will be displayed transaction's screen variants ,
    for sold to party field select copy with content.
    for other fields add checkmarks as per your requirement.
    Save transaction variant.
    If you want only that variant is to be run everytime VA05 is opened set it as standard else better choice is to allow users to run out of vailable variants ,
    Just take care to give appropriate name ans description for easy understanding of enduser.
    You can work it similarly with any variant.
    Regards
    MAndar

  • After updating, I'm unable to save changes in InCopy.

    I just updated my InDesign and InCopy to the latest versions. Both my client and I are unable to save in InCopy because that command is now grayed out. Saving works in InDesign. When the client checks in the content, I can see his changes even though he isn't able to save them. Any ideas on how to get the save command to work again?

    I'm going back to Internet Explorer

  • Saving JTextPane contents to a File (Images Also)

    How do I save the contents of a JTextPane which contains Images ?
    When I try to save, it just saves the text part skips images.
    Could someone write a little sample code here ?
    Thank you.
    Edited by: Butters on Mar 15, 2008 5:29 PM

    You get the image, and then write it out. If you are saving loading the images yourself, then save the image before you loose all references to it--while you still have the image in memory, not from the JTextPane.

  • Cannot save iWeb content

    I need help....I am working on a website for my church and everything was working great when yesterday it suddenly decides that it will not save any changes I make in iWeb. It will give me the little color wheel when I click 'save' but then says it is unable to save content. Any ideas out there on this? Also if I try to Publish all to .Mac it will tell me the same thing and not publish. Any help would be greatly appreciated.

    Another update....I got iWeb to work again for a little over a week by not using iWeb Enhancer. But after making a few changes the other day to the site, I started getting the same error again; 'The document "iweb" could not be saved'. I did not use iWeb Enhancer in any way so I am now beginning to think that Apple Support was wrong about that program. But it still leaves me unable to do anything to the website yet again. Any ideas or help from anyone would be greatly appreciated.

  • Unable to save the ALV layout variant and display of selection screen on F4

    Hi All,
    The end user wants to directly select the layout variant (SLIS_VARI). I have used the following code to display the layout variant on selection screen. But, I am unable to save the variant on ALV. Whenever I am trying to select the layout variants (by doing F4 on selection screen) its displaying "No Layout found".
    Following is the code for displaying layout variant:
    PARAMETERS: p_var TYPE slis_vari.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_var.
      PERFORM f4_variant CHANGING p_var.
    FORM f4_variant  CHANGING c_variant TYPE slis_vari.
      DATA: ls_variant TYPE disvariant,
                l_exit     TYPE char1.
      ls_variant-report = sy-repid.
      CALL FUNCTION 'REUSE_ALV_VARIANT_F4'
        EXPORTING
          is_variant = ls_variant
          i_save     = 'A'
        IMPORTING
          e_exit     = l_exit
          es_variant = ls_variant
        EXCEPTIONS
          not_found  = 2.
      IF sy-subrc = 2.
        MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ELSE.
        IF l_exit EQ space.
          c_variant = ls_variant-variant.
        ENDIF.
      ENDIF.
    ENDFORM.                    " f4_variant
    and following is the code for displaying the ALV:
    FORM edition_alv.
      ws_variant2 = ls_variant.
    * Call ALV editor in list mode
      IF p_list = 'X'.
        CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
          EXPORTING
            i_callback_program      = ws_extract1-report
            i_callback_user_command = ws_user_command
            is_layout               = ws_layout
            it_fieldcat             = wt_fieldcat
            it_sort                 = wt_sort
            i_save                  = 'A'
            is_variant              = ws_variant2
            it_events               = wt_events[]
          TABLES
            t_outtab                = wt_edition.
    * Call ALV editor in grid mode
      ELSE.
        CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
          EXPORTING
            i_callback_program      = ws_extract1-report
            i_callback_user_command = ws_user_command
            it_fieldcat             = wt_fieldcat
            it_sort                 = wt_sort
            i_save                  = 'A'
            is_variant              = ws_variant2
            it_events               = wt_events[]
          TABLES
            t_outtab                = wt_edition.
      ENDIF.
    ENDFORM.  
    I am not sure whats going wrong, but I am unable to save variants.
    Please help.
    Thanks,
    Vishal.

    The F4 will display you the existing layouts only. So you need to save the layout first & then execute the report again & check if you are getting F4 values for that field.
    The Layout needs to get stored with variant.
    Regards,
    Mahesh

  • Unable to save data entered in editable field of IW37N output

    Hi Gurus,
    I have made one of the fields in IW37N ALV output as editable using exit IWOC0004. When I enter the values in the field, I am unable to save the data to the order. The orders are getting successfully released but the values entered are not saved in database. Please help.
    Thanks,
    Pramod.V

    Discovered that the problem was with the Adobe version. Updated version to 8.1.1 and installed  Active X control software and things started working.

  • Unable to save data in record working time

    Hi All,
    I am working on ESS portal , when I try to record & save working time in portal , it throw an error message as 'Unable to save data'.
    Can you plz assist me on this.
    Usefull answers will be awarded.
    Thanks,
    Nilima

    Hi ALL,
    I'm too facing the same problem....usefull answers will be awarded.

Maybe you are looking for

  • How many users here actually know when a problem occu

    Like some users say "I got no problem"Do they actually know for a fact there is?no problem?Try to imagine someone driving with the E-brake on in their car. Did they notice?NO?Was it damaging?YES??

  • [SOLVED] ATI drivers Help needed

    Hi guys i am getting catalyst-utils and mesa-libgl are in conflict (libgl). Remove mesa-libgl? when i try and remove the using "Y" it failed also same with pacman -R [admin@localhost ~]$ sudo pacman -S lib32-catalyst-utils [sudo] password for admin:

  • Why in Saudi Arabia the maps are not working

    In Saudu Arabia if we want to get the routes message showing " Directions Not Available"

  • Lightroom processes for ages after withProlongedWriteAccessDo

    Hi, I am considering a switch from Expression Media to Lightroom, and I wrote for that a Lightroom plugin that imports all my metadata from an EM XML file. Functionaly, it works great. However, I have a performance issue problem: if I run the plugin

  • HELP!!! Aperture can't find original files!

    Help!!! I imported a 64 Gig SD Card into Aperture for an engagement shoot. It imported the files, about 2,000 CR2 files.  I had to clear the SD card to do another shoot.  When I returned to Aperture, it shows a thumbnail of the file, but yellow excla