Editor Kit Mystery behavior. I don't get how this works.

I build a JTextPane which is editable, save it to a file, and load it back after which it's editing behavior is completely whacked out.
The text region is originally built like this:
        textRegion = new JTextPane();
        StyledDocument doc = textRegion.getStyledDocument();
        MutableAttributeSet attr = new SimpleAttributeSet();
        StyleConstants.setForeground(attr, Color.black);
        if ( text!=null ) {
            try {
                doc.insertString(doc.getLength(), text, attr);
            catch (BadLocationException ble) {
                System.err.println("Couldn't insert initial text into text pane.");
        ...After which I can edit the text and change font, size, color, bold, and italic.
Then I save the contents as a string put into a larger XML file like this:
    public String getXmlText() {
        // translate content and all its embedded style attributes into XML
        // Using class: MinimalHTMLWriter
        CharArrayWriter writer = null;
        try {
            writer = new CharArrayWriter();
            MinimalHTMLWriter htmlWriter = new MinimalHTMLWriter(writer, (StyledDocument)textRegion.getDocument());
            htmlWriter.write();
        catch (IOException ex) {
            System.out.println("Save error");
        catch (BadLocationException ex) {
            System.out.println("HTML File Corrupt");
        finally {
            if (writer != null) {
                writer.close();
        return writer.toString();
    }Then I reload the contents from HTML String in the saved XML file like this:
    public void setXmlText( String text ) {
        // Translate HTML in "text" into styled document
        System.out.println(text);
        CharArrayReader reader = new CharArrayReader( text.toCharArray() );
        textRegion.setContentType("text/html");
        textRegion.setText(text);
    }After which the editing of the text in the JTextPane is completely messed up.
For example, I type the text "16 point", highlight it and set it to 16 point
font and what ends up in the saved document looks like this:
        <p>
          <span style="color: #000000; font-size: 18pt; font-family: Dialog">
            1
          </span>
          <span style="color: #000000; font-size: 18pt; font-family: Dialog">
            6
          </span>
          <span style="color: #000000; font-size: 18pt; font-family: Dialog">
          </span>
          <span style="color: #000000; font-size: 18pt; font-family: Dialog">
            p
          </span>
          <span style="color: #000000; font-size: 18pt; font-family: Dialog">
            o
          </span>
          <span style="color: #000000; font-size: 18pt; font-family: Dialog">
            i
          </span>
          <span style="color: #000000; font-size: 18pt; font-family: Dialog">
            n
          </span>
          <span style="color: #000000; font-size: 18pt; font-family: Dialog">
            t
          </span>
        </p>Not only the wrong font size, but it puts paragraph tags between every single character I type! Why is this behaving so strangely?
Thanks for any insights.
--gary                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Thanks,
Well I guess there's always the solution of parsing out the HTML tags and rebuilding the document by applying styles, the way it was built in the first place.
--gary                                                                                                                                                                                                                                                                                                                                                               

Similar Messages

  • HT1481 i dont get how this works

    i forgot my pass word from my ipod, and its says ( IPOD IS DISABLED ). how can i take that off???

    You'll need to connect the device to iTunes and restore it.  If iTunes doesn't recognize the iPod still, try manually placing it in recovery mode first and then performing the restore in iTunes. See this article for instructions on putting the iPod into recovery mode.
    iOS: Unable to update or restore
    B-rock

  • HT201272 I don't see how this works for an iPod

    I have an iPod Touch running iOS 5.1.1 and have a few aps that I have downloaded and then deleted and now I want to reinstall them on the iPod. The example of the App Store app bottom menu bar shown above is not like the menu bar on my iPod. My iPod does not have a "purchased" or "genius" menu heading. A lengthy internet search comes up with a scary solution of backing up the iPod, deleting iTunes on my Mac, re-installing iTunes and restoring the iPod. I fear losing all of my movies, songs, apps, podcasts and photos. Simply re-checking the box on iTunes does not work. Neither does restoring the iPod. It seems, once an app is deleted from a device, it is no longer able to be used on that device ever.

    Most of the screen shots in that article are for the iPad. For an iPod touch you would go to the updates section at the bottom of the App Store screen and in there you will find the purchased section you seek.

  • Any file I open, along with the color swatches and sampler, in PS has a warm white color where it is supposed to be white. I don't now how this happened and I have no idea how to get the whites back. Please help, thanks, P

    as I stated. the white in any file I open in PS s a warm white. I don't know how this happened or how to fix it. I do know it is not my PC or moniter. Only in PS. any hepl is appriciated, thanks, P

    My5cats, Cris may have more to add but here are some thoughts.  A calibrated monitor does have warm whites.  We perceive a blue white as being correct but it isn't.   i don't know if you are using monitor calibration or not.   One possible area is that Photoshop is set to a paper or some other gamut.  You can check (in PS) by going to the Edit menu > Color settings.  Here is a picture of mine.  I set the working space to sRGB which is used for the web and many printers.  If you get a correct setting , consider saving it.

  • Home page i cons mail, i pod, messages etc are twice the size as normal. don't know how this happen and can't fix it, help!

    My I phone 4 G home page i cons are twice the size as normal (mail, messages, ipod) etc.
    Don't know how this happened and can't fix it help.

    Double tap with THREE fingers to turn zoom off. Then go into: Settings>General>Accessibility and turn it off for good.

  • TS3276 On the left side of the mail page there is an "On My Mac" header with several folders included. One of the folders, in white, is one called "recovered mail" I don't know how this got there and am not able to delete it. Not receiving any email now.

    On the left side of the mail page there is an "On My Mac" header with several folders included. One of the folders, in white, is one called "recovered mail" with 843 messages in it. I don't know how this got there and am not able to delete it. I am also no longer receiving any email now. Help!

    set the wake-on lan on the main computer
    The laptop's too far away from the router to be connected by ethernet. It's all wifi.
    No separate server app on the laptop, it's all samba
    The files are on a windows laptop and a hard drive hooked up to the windows laptop. The windows share server is pants, so I'd need some sort of third party server running. Maybe you weren't suggesting to use Samba to connect to the windows share though?
    I'm glad that you've all understood my ramblings and taken and interest, thanks The way I see it, I can't be the only netbook user these days looking for this kind of convenience, and I certainly won't be once chrome and moblin hit the market.
    Last edited by saft (2010-03-18 20:38:08)

  • I don't know who "sailsalot" is, but it's not me.  I am gags76.  I keep getting responses from you about an iphone.  I have an ipad and have gotten help from you before.  I once used "sailsalot" as a nickame on Skype.  I don't know how this happened.

    I have a new ipad and have used the community to answer questions for myself.  Your help has been great!  I don't know how you got my sailsalot name from my Skype account but I signed in with you as "gags76" and got help with my new ipad.  I discovered I used a different Apple id and password on my ipad from my computer (imac) and changed that.  My e-mail is **********. Could you email me if there is something I should do at my end.  I have to use itunes to sync with my ipad so I have been going back and forth between the two.  Should I sign in with my proper Apple id on my ipad?
    <E-mail Edited by Host>

    sailsalot wrote:
    I have a new ipad and have used the community to answer questions for myself.  Your help has been great!  I don't know how you got my sailsalot name from my Skype account but I signed in with you as "gags76" and got help with my new ipad.  I discovered I used a different Apple id and password on my ipad from my computer (imac) and changed that.  My e-mail is   Could you email me if there is something I should do at my end.  I have to use itunes to sync with my ipad so I have been going back and forth between the two.  Should I sign in with my proper Apple id on my ipad?
    Yes

  • When I open my bookmarks I have them but then I have a bunch under my normal bookmarks that say "show in sidebar" and "organize bookmarks" I don't know how this happened and I don't know how to get rid of them.

    the above explaines it pretty well.

    An add-on is probably causing that.
    '''Try the Firefox SafeMode''' to see how it works there. <br />
    ''A troubleshooting mode, which disables most Add-ons.'' <br />
    ''(If you're not using it, switch to the Default Theme.)''
    * You can open the Firefox 4.0+ SafeMode by holding the '''Shft''' key when you use the Firefox desktop or Start menu shortcut.
    * Or use the Help menu item, click on '''Restart with Add-ons Disabled...''' while Firefox is running. <br />
    ''Don't select anything right now, just use "Continue in SafeMode."''
    ''To exit the Firefox Safe Mode, just close Firefox and wait a few seconds before using the Firefox shortcut (without the Shft key) to open it again.''
    '''''If it is good in the Firefox SafeMode''''', your problem is probably caused by an extension, and you need to figure out which one. <br />
    http://support.mozilla.com/en-US/kb/troubleshooting+extensions+and+themes
    ''When you figure out what is causing that, please let us know. It might help other user's who have that problem.''

  • After recent Add-Ons, don't get "Download this video" box in You Tube.

    Cyberfolk:
    I always used to get "Download this video" before, but after several recent ADD-Ons (w/in a month or two), it no longer appears above the You Tube screen. This forces me to use Internet Explorer. Pls advise in relatively plain English, as I am a (10-yr )relatively computer literate, old school, 72-yr old cyberdude. (I was born before WW II, for Pete's sake!)
    Thanks hopefully,
    Lowtech Bob

    I had this exact problem a couple of days ago. The workaround was rather easy:
    Just go to the add-ons-manager and install some random add-on from addons.mozilla.org. Once you restart Firefox, all the add-ons are back in the add-ons-manager, but they are disabled. Just enable them all, and you're back to normal.
    All the settings, icons, etc., of the different add-ons are still there.

  • Every time I open Firefox or a new Firefox window, my home page opens but so does a second tab showing the LinkedIn login page. Don't know how this started happening or how to stop it.

    Figured it out. There was code in the Preferences/home page field telling it to open my home page and that page at the same time in two tabs. Don't know how it happened, but is fixed now.

    Yeah, I don't know why I can't find my posted problem of November 18, but it was similar, and I also figured out how to fix it. IF when you open Firefox to your homepage and MORE opens than IS your homepage, then go to tools, options, and check your homepage info. You will find the URLs to your homepage plus whatever windows are opening that you do NOT want. Delete everything but the homepage and close. I had at least 10 windows opening from a browsing session over a week ago every time I opened Firefox... aggravating!

  • Where is my manual i don't know how to work my computer?

    Where is my manual I don't know how to use this computer?

    You can download a copy of the manual for your computer at the hp.com support section for your model, if you're uncomfortable looking for it on your own you should be able to ask a friend or family member for help.

  • Aaagh! Help needed with tabs, I just don't get how to use them.

    I have done a search for a beginners guide on how to make the following setting, without any luck, so I felt the need to start a new topic.
    I am writing a contents page for a collection of poetry and I have (so far) written out those contents so they are aligned to the left of the page. So there is a number bullet, then the title of the poem, as follows:
    1. Abend
    2. Der Allwissende
    3. Im hohen Alter
    What I want is to put the page number for each poem (each poem has it's own page), on the same line, but aligned to the right side of the page. Like this:
    Introduction +Page 5+
    1. Abend 6
    2. Der Allwissende 7
    3. Im hohen Alter 8
    I should mention in case it's relevant, I am using text boxes for the contents pages.
    Hoping someone can help soon.

    Do as you have done. Set the lists style to "None".
    Then simply click on the ruler where you want to have tabs. To change the tab to left/right/centred or decimal keep clicking on the tab or right mouse click on the tab and choose which you want.
    So to create what you say you need, going from left to right.
    1. *A right tab* to catch the right edge of the number say 1cm from the left
    2. *A left tab* to catch the beginning of the text say 1.5cm from the left
    3. *A right tab* or decimal tab on the far right of the ruler to catch the page number
    To get rid of tabs just pull them away from the ruler and they disappear in a puff of smoke.
    You will need to type a tab at the beginning of each line with a number to push it over to the first (right hand) tab.
    Refinements are:
    1. *Hanging indent.* This makes the number sit to the left and the following paragraph to align to the 2nd tab. Do this by sliding the left margin stack to the position of the 2nd tab, then drag the flat bar on the top back to the left margin.
    2. *Leading tab.* In +Inspector > Text (4th tab) > Tabs > Click on the 3rd tab in the list > Leader > Choose line style+
    Just the usual reminder that tabs are a style attached to whatever paragraph that you are in and continue on with every return until you change them to something else.
    Having set up these tabs the way you like them, it would be a good idea to turn them into a named paragraph style for reuse elsewhere.
    Peter

  • IPhoto some of my photos have gotten very small.  I don't know how this happened and I can't get them back to normal size.  Any ideas?

    I have a large iPhoto library, personal.  Some of my older photos have downsized to be very small.  I am unable to get them back to normal size.  I do not know how or when this happened and don't know if I did something to cause it.  I have upgraded computers several times.  Currently have a 2011 model 27" iMac with 10.7.4.  Any help would be appreciated.
    gerryjet

    Some of my older photos have downsized to be very small.
    Can you explain what you mean by this? Dimension? File size?

  • I don`t know how to work the new itune , i can`t download music  , and it`s to complacated, everyone i knows feel the same way . and i want to be able to down grade back to the old itunes , but it want work now. how can i get the older one back working ?

    I can`t download music from the new itunes ,it`s complacated ,and i would like to revert back to the older version . i`ve tryed over and over ,with no luck .just want to get back to the old easy way

    Everything works the same in the new version as in the old version.
    What happens when you try to download music?

  • I don't understand how this Forum works

    I have a question getting the proper version of Flash Player for my computer.  So I went to the Flash Player forum and typed my question into the question box. 
    But all I received was a notice saying that no similar questions were found (or something to that effect).  In other words, it did not let me ask my question to the Adobe FP community--it just did a run of the keywords in previous posts.
    I need to ask my question to the Adobe community and have just spent half hour going around in circles.  Can someone please tell me what I'm doing wrong? Thanks.

    Because they want very few people to use their forums so that answering the questions becomes as easy as possible.
    That has not been the impression left on me. Recently, Adobe initiated a special department, to better manage the forums, as Adobe realizes the service that they provide. Much has been done to simplify, and coordinate the tasks of using the forums, with some fairly major re-designs.
    Have all those efforts been perfect? I rather doubt it, but the process is on-going, with many discussions on how to make the forum "experience," both easier and more satisfying to users - both those who post with problems and questions, and for those who answer the questions. Not every change has improved things for everyone, and I have had a few complaints on some. Still, the effort (and expense) is being put forth. Many are working very hard, and there have been improvements, with more to come. The forums will never be perfect for all users. That is just the way that it is. However, with a focus on "the greater good" of the "majority," then that might be, as good as it gets.
    Hunt

Maybe you are looking for