Trouble inserting text into JEditorPane

Hello.
I am trying to use a URL Connection and the read method to produce an HTML page in a JEditorPane.
     purlRec is a data record that contains information relating to the URL in question.
     pis is an input stream create from the URLConnection.getInputStream() method
private void loadFromURL(UrlRecord purlRec, InputStream pis ) {
URL url;
String tmpStr = (String)purlRec.getUrlName();
String baseUrl = (String)purlRec.getUrlName();
setContentType("text/html");
try {
HTMLDocument doc = (HTMLDocument)getDocument();
doc.setBase(new URL(baseUrl));
this.read(is,doc);
repaint();
catch (Exception e) {
System.err.println("Couldn't create URL: " + tmpStr);
System.out.println("error:"+e.getMessage());
I get the following when I execute the code. Am I not using this correctly or is there something I am missing? I am using the read from input stream so that I can connnect to url that require authentication. I know that the URL connection works because I am able to write the output of the stream to a text file in a test function.
Couldn't create URL: http://www.google.com
java.lang.RuntimeException: Must insert new content into body element-
     at javax.swing.text.html.HTMLDocument$HTMLReader.generateEndsSpecsForMidInsert(HTMLDocument.java:1878)
     at javax.swing.text.html.HTMLDocument$HTMLReader.<init>(HTMLDocument.java:1854)
     at javax.swing.text.html.HTMLDocument$HTMLReader.<init>(HTMLDocument.java:1729)
     at javax.swing.text.html.HTMLDocument$HTMLReader.<init>(HTMLDocument.java:1724)
     at javax.swing.text.html.HTMLDocument.getReader(HTMLDocument.java:125)
     at javax.swing.text.html.HTMLEditorKit.read(HTMLEditorKit.java:228)
     at javax.swing.JEditorPane.read(JEditorPane.java:504)
     at javax.swing.JEditorPane.read(JEditorPane.java:478)
     at com.UrlChecker.panels.HTML.EditorPane._$34246(EditorPane.java:105)
     at com.UrlChecker.panels.HTML.EditorPane.changeUrls(EditorPane.java:142)
     at com.UrlChecker.demo.UrlChecker.changeHtml(UrlChecker.java:131)
     at com.UrlChecker.panels.Report.URLTabView.mouseClicked(URLTabView.java:91)
     at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:208)
     at java.awt.Component.processMouseEvent(Component.java:5096)
     at java.awt.Component.processEvent(Component.java:4890)
     at java.awt.Container.processEvent(Container.java:1566)
     at java.awt.Component.dispatchEventImpl(Component.java:3598)
     at java.awt.Container.dispatchEventImpl(Container.java:1623)
     at java.awt.Component.dispatchEvent(Component.java:3439)
     at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3450)
     at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3174)
     at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3095)
     at java.awt.Container.dispatchEventImpl(Container.java:1609)
     at java.awt.Window.dispatchEventImpl(Window.java:1585)
     at java.awt.Component.dispatchEvent(Component.java:3439)
     at java.awt.EventQueue.dispatchEvent(EventQueue.java:450)
     at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:197)
     at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
     at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144)
     at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)
     at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)
error:Must insert new content into body element-
Thank you

I tried using this, but I get an UNAUTHORIZED Status code (401) indicating request requires HTTP authentication. ( HttpServletResponse error code ). This is why the encoded authentication is used. It works when I try to just read from the url using an InputStream but not when I try passing the same InputStream to the JEditorPane.
Any Idea of how to use JEditorPane.read(InputStream in , Object desc) or why it would work in one instance and not in the other?
Thanks

Similar Messages

  • Inserting text into a field at the current cursor position

    Does anyone know how to insert text into a field at the current cursor position? I would like it to work similar to the Syntax Palette in Forms. I cannot figure out how to retrieve the current cursor position in order to manipulate the text.
    Any help would be great.
    Thanks.

    Hi,
    If the button and the textfield are on in the same subform then this code should work in the click event of the button
    (This is JavaScript code so make sure the code is set to JavaScript and Client on the drop downs in the script window)
    (assuming the name of the textfield is TextField1)
    TextField1.rawValue = "some value";
    If they are in different subforms then you have 2 options
    Please note in both these options it is easier if the subforms have names ( I am assuming this to keep samples simple)
    option 1 -
    use the parent object to move up the tree till you are at the same level as that of the subform that contains the textfield
    e.g. 
    (Click Event of the button)
    this.parent.subformname.TextField1.rawValue = "some value";
    option 2 -
    Use the resolve node to make your way down from the top level of the form
    xfa.resolveNode ("form1.subformname.TextField1").rawValue = "some value";
    Hope this helps
    Malcolm
    p.s. I am making assumptions as the image/file you attached did not appear for me.

  • Inserting Text into a web page

    I need to know how to insert text into a webpage, like google, search, and then get the result.
    Using the wonders of the internet I have been able to display a webpage, and see the HTML code that is generated, however, I don't know how to insert text into a web page, or get the result.
    Any help, or pointing into the right direction would be appreciated.

    What do you mean by insert into web page? Like
    prefill data on a form?
    Or like a search on google? What are you using to
    do this?
    I am guessing based on the info you gave in your
    question, that you might want to just look at the url
    of the page. For example search on google and you
    will see the text entered into the search field
    inside the url. Learn from that and develop a url
    that will search for the text you want to insert.
    If I am not understanding you, please clarify.Right now, I'm using the URL to search for me, which will work, but the search can be different from website to website, and I would like something closer to an automated form filler if I need to implement something like this again.
    Of course, something like an automated form filler would probably work better, if I were able to retreve the results

  • Inserting text into table cells in Powerpoint

    Hi
    I have a named table ClientInfo on Slide 3 in Powerpoint. How can I programmatically insert text into the table's cells?
    Thanks
    Regards

    Hi Yahya,
    What did you mean named table? Did you mean the name of shape?
    If I understood correctly, we can use table object to manipulate a table shape on a slide. And here is a sample to insert text into the first cell for your reference:
    Application.ActivePresentation.Slides(3).Shapes("ClientInfo").Table.Cell(1, 1).Shape.TextFrame.TextRange.Text = "Hello"
    Also here are some helpful links for learning PowerPoint developing:
    How do I... (PowerPoint 2013 developer reference)
    Object model reference (PowerPoint 2013 developer reference)
    Regards & Fei
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Cant insert Text into a TextBox. (Confusing Problem, CS6)

    Hello forum members!
    Just got the trial today and I am trying to insert text into a document. I press "T" and drag a box for a textbox. I then double-click inside that box to type something, and whatever I type absolutely NOTHING appears. It just blinks and nothing is actually typed inside the box.
    This is really frustrating. I have only just started and have one document that is fresh, so my question is what is the problem here?
    Thanks in advance,
    Shane Stocks

    Could you elaborate on that a little? I have taken a screenshot of my screen to show you how everything is. I have not touched any settings and have literally downloaded the trial about an hour ago.
    I do this. Click on the T, drag a box, then start typing. When I type, the icon does not move, and for some reason it seems what I am typing renames the layer tab. Please view the image, everything is there.
    Thanks again,
    P.S. The text-box does dissapear when the icon changes into a text icon, and the image above is me typing random things. Nothing appears.

  • HT2488 How to I insert text into a this command in automator wine "Text goes here" this is a perl script

    I have spent hours trying to figure this out, automator is the hardest thing to figure out. All I want to do is emulate me doing this
    -Open terminal
    -type wine
    -drag and drop the location of an .exe file
    -hit enter
    Now this should be easy as all I have to do is do run shell script, insert argument and done, BUT IT DOESNT RECOGNIZE WINE!?!?! Pleas help me.
    Let me clarify.
    If I make an automator application that that runs the command "wine" and then inserts text into the space after that Then i will be set. But no matter what I do nothing works. If i set the shell to perl and pass input as argument....It doesnt work the $f and $@ stuff doesnt work.
    Wine is likely not recognized because is is pearl based so I set it to pearl, but how do i pass and argument over to it?

    Try
    /opt/local/bin/wine "$@"
    The "..." will protect the white space, but still allow $variable subsitutions.
    The $@ will substitute all the files you drag as a group to your Automator app.
    The notation "$@" does the substitution with each file properly quoted to protect the white space in the file path, but provide each file as its own quoted argument to the 'wine' command line.
    If you need to invoke 'wine' once for each file of a group of files you drag on to your automator app, then use
    for f in "$@"
    do
         /opt/local/bin/wine "$f"
    done
    This will loop through each file of a group of files you drag onto your automator app, and invoke 'wine' once for each file in the group.

  • Freeform to Text: How to insert Text into freeform

    How to edit text into freeform

    Hi FZRR,
    Could you share more information with us? Or you can upload the screenshot to OneDrive and share the picture link here.
    If you want to insert text into freeform shape, there are two methods:
    1. Insert a textbox on the freeform shape, edit text in the textbox.
    2. Select the freeform shape, and right-click > Add text.
    If there is anything I can do for you regarding this issue, feel free to post back.
    Best regards,
    Greta Ge
    TechNet Community Support
    It's recommended to download and install
    Configuration Analyzer Tool (OffCAT), which is developed by Microsoft Support teams. Once the tool is installed, you can run it at any time to scan for hundreds of known issues in Office
    programs.

  • Inserting text into a Pages document with Applescript

    I want to create a Pages document from a custom template but be able to insert text at various points in the document (inputted data under headings etc). I would like to use Applescript but cannot get insertion points to work, is this possible? As usual, all help gratefully accepted.

    I have made a Pages template that contains tables and I want to enter text into sections of these tables
    That's a completely different story! But that's still possible using GUI Scripting. Here's an example:
    tell application "Pages"
        activate
        select table 1 of body text of front document
        tell application "System Events" to tell process "Pages"
            set theWindow to window 1 whose role description is "standard window"
            click button "Table" of tool bar 1 of theWindow
            keystroke "Cell A1"
            keystroke tab
            keystroke "Cell B1"
            key code 125 -- down arrow
            keystroke "Cell B2"
            -- and so on
        end tell
        select insertion point after table 1 of body text of front document
    end tell

  • Inserting text into JTextPane

    I have a requirement where I need to insert some text into a JTextPane within its DocumentListener. I read somewhere that this is not a good practice. What would be the right way of doing this?
    Basically, I'm listening to what user is typing and helping him by inserting some text automatically based on user choice.
    Please provide code samples.

    Hmmm - not knowing anything about the document listener - maybe they were talking about some kind of loop, where you insert text and then it triggers the listener to insert text which triggers the listener to insert text.... etc.
    Maybe there are some other user input listeners, such as the keyListeners which might be better?
    I haven't even had a look at the JTextPane API at the moment, so I don't know what I'm talking about.
    Cheers,
    Rene

  • Insert sentences into JEditorPane

    Hi,
    I am trying to insert a user input sentence into JEditorPane. Before that, the user will type a word which is search for in the JEditorPane. when the word is found in a sentence, the user's input sentence is inserted to be the line juz after the line with the keyword.
    from http://forum.java.sun.com/thread.jspathreadID=650821&messageID=3827757
    i learnt how to find the line which contains the keyword, but how do i push the subsequent lines downwards, and insert the user's sentence in between them??
    Regards,
    yiming

    I am on a roll this morning.
    I am still pulling my hair out with the kit but here is what I did.
    First get the editor kit. If you traverse the code there are a lot of actions that are built it.
    I grabbed these actions in the following manner.
    HTMLEditorKit kit = new HTMLEditorKit();
    Map _editActionMap;
    Action[] action = kit.getActions();
    for ( int iIndex = 0; iIndex < action.length; iIndex ++ ) {
    // if you want to see the action name.
    System.out.println( action.toString());
    // Build a convient hash of the actions by name.
    _editActionMap.put( action[iIndex].getValue( Action.NAME ), action[iIndex] );
    Now you have a map of all the built in actions. Guess what insert table is in the list. Do see the rest just iterator through the list and print them out.
    Now you have the actions.
    Add the action for insert table to a pop up menu.
    tableMenu is a JPopmenu menu.
    JMenuItem menu;
    menu = tableMenu.add( (Action)_editActionMap.get( "InsertTable" ));
    menu.setText( "Insert Table" );
    The default label is the actions name. So I simply rename the pop menu title.
    Cut, copy, paste, bold, italic are also in there.
    Regards
    Carl

  • Can't insert text into web page plus script error message

    I'm using CS3 and, on a fairly regular basis, when I am either pasting or inserting content (usually a newsletter of 500-1000 words), I get a message saying something like I can't insert text in this area. I definitely can insert text in the area as I have done it tons of times before. I sometimes have to cut and past a doc line by line to get it to insert. Very frustrating!
    Also, just recently, I've been getting a script error message, "An error has occurred in the script of this page" followed by Line: 992, Char: 106, Error: Unterminated String Constant, followed by the question: Do you want to continue running scripts on this page? I click Yes and everything seems to work fine.
    Help on either would be appreciated.
    Thanks in advance.

    You might want to make sure you are trying to copy plain text. It's possible that if you are copying from a Word document or another Web site that you are bringing along extra unseen code it doesn't like.  Try copying into Notepad first and then copying from Notepad into Contribute.  Not sure if that's the problem or not, but that's what came to my head first.
    I used to get an error that sounds similar (however it's not reproducing the error for me right now) to your error.  It was because some of my users had javascript menus on their page that Contribute didn't like.  However, if worked fine when you clicked yes and it was fine once it was published.   So if you are running a script that's probably why and I wouldn't worry too much about it as long as you can continue working and the page displays to your users correctly once published.  It's just annoying.
    Hope that helps.  Good luck.

  • Inserting text into existing text in Powerpoint

    Hi
    I have a text like "I have included xxx in the quote." in a slide. How can I insert text such as '8 items per head' in place of xxx via code?
    Thanks
    Regards

    Hi,
    >> How can I insert text such as '8 items per head' in place of xxx via code .
    You can use Replace () method to replace "xxx" .Here is the sample code for you , which you can refer to replace "XXX" in the textRange in your PowerPoint  
    Set myDocument = ActivePresentation.Slides(2)
    Dim str
    For Each s In myDocument.Shapes
    If s.HasTextFrame And s.TextFrame.HasText Then
      str = s.TextFrame.TextRange.Text
      s.TextFrame.TextRange.Text = Replace(str, "xxx", "8 items per head")
       End If
    Next
    Best Regards
    Lan
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Inserting HTML into JEditorPane

    I have a window with a JEditorPane on top and a JTextField below it. I need to be able to type raw HTML into the edit field and have it appended to the HTML document displayed above.
    For example if I type...
    This is <b>bold
    I need to append that to the document. However I want the style to stick. Notice I did not close the tag above. I want the next line I enter into the edit field...
    and so is this but not</b> this.
    I want this to appear bold up until the closing tag and then return to normal. The problem is that every time I append new text to the document the style is restored to normal.
    I insert the text with the following code. I send the contents of the JTextField to the following function when I hit return.
    void processInput(String input) {
    try {
    HTMLDocument doc = (HTMLDocument) output.getDocument(); // output is my JEditorPane
    editor.insertHTML(doc, doc.getLength(), input, 0, 0, HTML.Tag.BODY); // editor is HTMLEditorKit
    // relevant catch clauses
    Basically I want the two broken input sequences to appear in the editor as one seamless entry. I want to be able to type these two entries and have them show up as if they were entered as one entry.
    entry 1:This is <b>bold
    entry 2: and so is this but not</b> this.
    I want to somehow cause this to be displayed as if I typed...
    This is <b>bold and so is this but not</b> this.
    Is there a way I can do this?
    Thanks.
    -Russ

    as i understand you you want to write
    entry 1:This is <b>bold
    entry 2: and so is this but not</b> this.
    in two lines
    Try this
    entry 1:This is <b>bold<br>
    entry 2: and so is this but not</b> this.

  • Inserting text into a PDF

    Greetings all!
    I'm quite new to InDesign, but I'm thrilled to see such a vibrant community on the official forums. I'm getting along quite well with it, absolutley awesome program, I may be in love...
    But, I've hit something of a problem. I'm making a digital sales brouchre, 99% of the text it it will remain the same, but there are a few sections where text will need to be changed by the sales guys in our office (client name, client requirements and costings)
    Acrobat Pro is too expensive for such simple edits, and I've tried inserting form fields as a workaround but found out that you cannot change the font from Times!
    I'm using InDesign CS6. Is there anything I can do to make these small sections easily editable? This document will be edited by end users so needless to say it needs to be simple!
    Failing that is there any way the text can be inserted dynamically? For example, the sales guys insert the text and costs into a web form, and the PDF is spat out at the other end?
    I know PDF's are finalised files, but I hope there is an adaquate workaround! Anything to get them to stop using Microsoft Word!!!

    Hi Mike,
    Thanks for taking the time to respond.
    The brochure is for digital use only, so I would need to find a way to edit it directly. It's only a simple edit, but I think I've found something.
    In the meantime, I'm using the (newly free!) version of Acrobat Pro 7 and using the TouchUp Text tool. Luckily the whole document displays correctly, and edits can be made. Although there are some limitations.
    For anyone having this issue you can download Acrobat Pro 7, along with the rest of CS2 totally free here: http://www.adobe.com/downloads/cs2_downloads/index.html
    This solution seems quite strong, but if anyone has a better solution, I'd love to hear it!

  • 'Inserting' text into a Text Field on event trigger in a static form

    Sorry if this seems like a silly question, but I've been struggling with it for a bit and I'm new to Adobe/JavaScript.
    I am building a static form (it must be static), and I want to have text appear/disapear based on an event trigger (mouseclick). I tried creating a floating text object inside of a static text object, but I'm not sure how I can make the string value for this change based on the event trigger. The only advice in the Adobe help was purely regarding FormCalc, which I can't use as this must be a static form. I tried using this code in the <script>, but it obviously didn't work as it was written from FormCalc code versus JaveScript;
    TextField.rawvalue = variable.value;
    What do you suggest in terms of being able to script this, so my static form will work? Thanks a billion if you can help!
    PS: I'm using Adobe 9, LiveCycle ES 8.2
    PPS: Also tried inserting the following into my trigger script;
                        xfa.resolveNode("form1.subform.TestField").rawValue= "Please Work";
                        xfa.layout.relayout("form1.subform.TestField");
    It also did not work.

    Hi,
    If the button and the textfield are on in the same subform then this code should work in the click event of the button
    (This is JavaScript code so make sure the code is set to JavaScript and Client on the drop downs in the script window)
    (assuming the name of the textfield is TextField1)
    TextField1.rawValue = "some value";
    If they are in different subforms then you have 2 options
    Please note in both these options it is easier if the subforms have names ( I am assuming this to keep samples simple)
    option 1 -
    use the parent object to move up the tree till you are at the same level as that of the subform that contains the textfield
    e.g. 
    (Click Event of the button)
    this.parent.subformname.TextField1.rawValue = "some value";
    option 2 -
    Use the resolve node to make your way down from the top level of the form
    xfa.resolveNode ("form1.subformname.TextField1").rawValue = "some value";
    Hope this helps
    Malcolm
    p.s. I am making assumptions as the image/file you attached did not appear for me.

Maybe you are looking for

  • Cl_gui_alv_grid-check_changed_data issue

    Hello, I am using method "cl_gui_alv_grid->check_changed_data" in an editable ALV program like this. module user_command_0100 input. data: l_valid type c.     case ok_code.      when 'EDIT'.       call method plan_grid->check_changed_data            

  • How to Make standard fields editable

    Hi, We have are requirement to make the standard fields (cost center, GL, expense type, amount) to be editable for Approver user role. Currently only Auditor role can edit some of the fields. Is this something doable using SDK? Thanks, Webster

  • Adding MenuListener to a Menu object

    hi everybody, i want to add a MenuListener() to a Menu object. I am aware that we cn add this listener to a JMenu object but my code mostly contains Menu objects and changing all of them is not very easy at the moment. i would also like to know that

  • Is there any way to install Win7 64bit onto a partition

    Is there any way to install Win7 64bit onto a partition from a Win7 CD? I have tried bootcamp several times and it won't work. I am running a late 2011 MBP 500gb hd, 2.7ghz i7

  • Mac mini Bluetooth Disappears After Installing 10.6.2

    Hello, After upgrading the family Mac mini to 10.6.2, the Bluetooth keyboard stopped working. - I noticed that the Bluetooth menu shows Not Available. - Then, looking to reconnect, opened System Preferences and saw that Bluetooth is gone from Hardwar