JEditorPane insert text at caret?

Does anyone know how to insert text at the current position of the caret in a JEditorPane?
Additionally, is there a way to insert text before and after a specific selection within a JEditorPane?
Am I using the right object for these types of purposes, or is there another Swing component that would be better suited?

I found my answer in: [http://forums.sun.com/thread.jspa?forumID=57&threadID=5264416]
               public boolean insertHTML(InEditorPane textAreaPane, String text, int offset) {
          HTMLDocument doc = (HTMLDocument) textAreaPane.getDocument();
          HTMLEditorKit kit = (HTMLEditorKit) textAreaPane.getEditorKit();
          boolean res = true;
          try {
               // kit.insertHTML(doc, offset, text, 0, 0, null);
               System.out.println("reading from string reader");
               kit.read(new StringReader(text), doc, offset);
               System.out.println(textAreaPane.getText());
          } catch (Exception e) {
               System.out.println("error inserting html: " + e);
               res = false;
          return res;
     }           But now I have kind of the oposite problem: when I type text in the panel, new lines are saved as '\n' instead of "<br>", so when I save the text and show it again I get one long line...

Similar Messages

  • Want to Insert Text at Beginning of a Paragraph Using GREP

    I'd like to find the beginning of a paragraph and insert a text (that uses a specific character style) into that paragraph. Below is how I've set up the find/change:
    It almost works. The phrase "SECOND ITEM IS FREE!" is inserted at the beginning of the paragraph, which is what I want. But the first letter of the word that was originally at the beginning of the paragraph picks up the character style used on the inserted text. How do I insert the text without changing the character style of the existing text?
    Thanks in advance for any ideas on this

    [Jongware] wrote:
    (Short) Can't be done.
    (Long) Well, it can, but not in a single replace. You'd have to first insert the text, then assign the correct character style.
    (Slightly longer) You are physically re-inserting that final character, and so it will get that character style assigned. The usual way of finding-but-not-marking is to use a positive lookahead; but that doesn't work, because you would end up with two locations (the caret and the lookahead), and InDesign's particular implementation of GREP does not allow that. (Or rather -- irritatingly -- sometimes it seems to work if you press the Find button, but then a Change All is not going to work.)
    So that's why you have to insert at least one character in the Find What, and re-insert it in the Replace With fields.
    If all instances of the specific paragraph style need the prefixed text in a specific character style, consider redefining the paragraph style's autonumbering to include text and character style. Redefine the style, and all instances in the current document are changed. All future uses of the style automatically use the prefixed text and style. To update existing instances of the style in other documents with the new definition, use load paragraph styles; to apply the new definition to to other documents in an InDesign book, synchronize the styles. Search Google for terms like "InDesign paragraph styles numbered lists," "InDesign load styles," and "InDesign synchronize styles in book," without quotes for details.
    HTH
    Regards,
    Peter
    Peter Gold
    KnowHow ProServices

  • TextArea Insertion at current Caret Position

    I am trying to figure out the best way to insert "text" in to
    a textarea at the current caret position. Anyone have tips for
    figuring out where to find this? In Flash you used to have
    CaretIndex,
    Im in the process of writing a code editor component, so
    first off Im capturing the TAB key event, and then will insert an
    actual TAB in the textarea... Right now I was just doing
    this.Editor.text = this.Editor.text + ' '; But this is a stupid
    stupid idea - so instead of appending it at the end, I need to
    insert it in the current caret position.
    Any tips would be greatly appreciated. Once I get it done, I
    will be releasing it under either the Apache or GPL license.

    Update: I have found
    var text:String = this.Editor.text;
    this.Editor.text =
    text.substr(0,this.Editor.selectionEndIndex) + " " +
    text.substr(this.Editor.selectionEndIndex);
    this.Editor.setSelection(this.Editor.selectionBeginIndex+1,this.Editor.selectionBeginIndex +1);

  • How can I insert text in a photo?

    How can I insert text onto a photo?  Before Lion used Command T. Have not installed Page or Numbers. Have Microsoft for Mac.

    Open the photo with Preview and select ⌃⌘T.
    (Also, take a look at: Skitch)

  • Script to find a specific section in file & insert text below - how?

    I am dealing with kind of a problem here - I am using pekwm as my window manager and I use menumaker to automatically update the menu on every startup. My problem is that the original pekwm, the first two sections called 'terminal' and 'Run' and the last two sections called 'Go To' and 'pekwm' are overwritten/modified by mmaker so that there's only the applications submenues and  'pekwm' with the 'Themes' section erased and I want to somehow preserve all that. I was thinking of creating a bash script that does the mmaker thing and then use 'sed' or 'echo' to insert the code back into the appropiate areas of ~/.pekwm/menu.
    All I really need to know is how to find a particular string of code in the menu file and insert a block of text below that line using sed or echo.
    Any ideas?
    Last edited by lostinpurdy (2010-07-10 02:32:38)

    Looks interesting. But I'd like to keep it as simple as possible and avoid the part with the extra textfiles and just insert the code text straight into the menu file, kind of like this:
    mmaker --no-desktop -vf pekwm
    sed {
            find-and-goto-line-below-'root menu'-declaration, insert-text {
                                                                                                           entry for 'terminal'
                                                                                                           entry for 'run"
           ~/.pekwm/menu
    sed {
             find-line-below-'pekwm'-submenu-declaration, insert-text {
                                                                                                       entry for 'themes'
           ~/.pekwm/menu
    Obviously it's not real code but it's just to outline how I'd like to have it. Just need to know the correct syntax to make it work. I don't care much for 'Go To' and the rest.
    Last edited by lostinpurdy (2010-07-10 03:48:10)

  • How to insert text in the text-id using BDC

    Hi Friends,
    I m using the BAPI to upload the data for a transaction .
    In that transaction there are some text id's are created to insert text like 'Container number'.
    I want to insert the text in that text id . But it not a field. Text ids are having object no and table and number .
    Is there any function like 'READ_TEXT' which we use to retrieve the text form text ids to write text in text ids ?
    So that I can use that function to insert the text in the text ids.
    Thanxs.

    Hi Umesh,
    READ_TEXT is used to Read the text , but SAVE_TEXT is used to save the text. but for reading or saving you need correct iD's and text objects.
    Regards
    vijay

  • How to insert text in existing file.?????

    how to insert text in existing file.?????
    my file contains simple text with numbers of lines having more then 10 MB size and it might be increase up to 100MB.
    i required to seek to spec. position and insert chunk of characters to file without overwriting existing one.
    I tried out with RandomAccessFile class Also.
    Pl. Suggest me way to insert String in existing file.
    Thanks ,
    Timir

    how to insert text in existing file.?????You can't "insert" text into an existing file. You can
    overwrite portions of an existing file or extend one by
    writing past the current end of file.
    If you want to insert text into a file you have to write
    out a new file.

  • 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 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 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 from a variable in actionscript

    what is it called when you insert text from a variable in actionscript?

    Your question is not clear.  There is no specific name for the process of inserting text from a variable that I am aware of.
    If you have a dynamic textfield that you have assigned an instance name to, let's say you named it "tField", then to assign a variable called "aVar" to that textfield you would use:
    tField.text = aVar;

  • How use SDK to insert text in indesign using c++

    Hello All
    I want to  use Indesign CS5.5 SDK  in my  c++ project first to create Indesign Document then insert text in textframe.
    How include SDK in my project ?
    Is it right method to create indesign Application using SDK.
    #include "IApplication.h"
    #include "ISession.h"
    # include "IDocumentCommands.h"
    virtual IApplication *  QueryApplication()=0 ;
    ISession *  GetExecutionContextSession();
    IApplication application(GetExecutionContextSession()->QueryApplication());
    It required so many .h file, first I copy .h file from SDK and put in Project directory but it give some error after including these .h file in project.
    There are so many directory(source,build,docs, etc.) in SDK.How include and use this SDK in my project to create Indesign Document.
    How include so many  .h file in my project ?
    I have already included SDK path in VisualStudio2008 ->Tools->Option->ProjectSolutions->vc++Directories
    Thanks.

    Hi Jongware,
    This is not correct in C# you have type cast all the object to another Object and then only we can access it in required format
    for example
    if want to get font in active Document
    InDesign.Application myInDesign=  (InDesign.Application) COMCreateObject("InDesign.Application");
    InDesign myDocument = (InDesign.Document)myInDesign.ActiveDocument;
    InDesign.ParagraphStyles pStyles = (InDesign.ParagraphStyle)myDocument.ParagraphStyles
    InDesign.ParagraphStyle pSteyls = (InDesign.ParagraphStyle)myDocument.ParagraphStyle
    for(int i =0;i<pStyles.Count;i++)
         pStyle = (InDesign.ParagraphStyle)myDocument.ParagraphStyles[i];
    public static object COMCreateObject (string sProgID)
        // We get the type using just the ProgID
        Type oType = Type.GetTypeFromProgID (sProgID);
        if (oType != null)
            return Activator.CreateInstance( oType);
        return null;
    like above content
    for selection content u have to type cast selection object.
    InDesign.Selection = (InDesign.Selection).myDocument.Selection;
    Console.Writeline(InDesign.Selection.Contents);
    but it showing error....
    like this you have to type cast all things in C# and you cannot simply get selection contents like app.selection[0].contents
    pls help me
    Thank you for your reply....
    R. Thangaraj

  • How to insert text in the middle of an existing textfile using java

    Hi,
    How to insert text in the middle of an existing textfile using java i/o streams??

    Mickie wrote:
    I shudn't delete the file...Then you will have the old file and the new file - do you want that?
    and I have to insert text not only at a single place ....got to do at many places in the text file!!then extrapolate on the procedure outlined in reply #1 .

  • Problem on inserting text from file to a clob column

    Hi! I'm having problem in inserting text read from a text file to a clob column in my table.
    Here's my code
    public void addSyllabusOutline(int syllid)
              CLOB objclob1 = null;
              CLOB objclob2 = null;
              String query = "SELECT outline, projoutline FROM Syllabus WHERE syllabusid = '"+ syllid +"' FOR UPDATE";
              try
                   System.out.print("Getting syllabus outline and projoutline clob locator...");
                   DBConnection dbconnbean = new DBConnection();
                   dbconnbean.openConnection();
                   ResultSet rst = dbconnbean.executeQuery(query);
                   if(rst.next())
                        objclob1 = (oracle.sql.CLOB)rst.getClob("outline");
                        objclob2 = (oracle.sql.CLOB)rst.getClob("projoutline");
                        Writer clobwriter1 = ((oracle.sql.CLOB)objclob1).getCharacterOutputStream();
                        String filename1 = "c:\\o1u2t3l4i5n6e7.txt";
                        File outlinefile1 = new File(filename1);
                        FileReader outlineFileReader1 = new FileReader(outlinefile1);
                        char[] cbuffer1 = new char[10 * 1024];
                        int nread1 = 0;
                        while((nread1 = outlineFileReader1.read(cbuffer1)) != -1)
                             clobwriter1.write(cbuffer1, 0, nread1);
                        //clobwriter1.flush();
                        clobwriter1.close();
                        Writer clobwriter2 = ((oracle.sql.CLOB)objclob2).getCharacterOutputStream();
                        String filename2 = "c:\\p1r2o3j4o5u6t7l8i9n0e.txt";
                        File outlinefile2 = new File(filename2);
                        FileReader outlineFileReader2 = new FileReader(outlinefile2);
                        char[] cbuffer2 = new char[10 * 1024];
                        int nread2 = 0;
                        while((nread2 = outlineFileReader2.read(cbuffer2)) != -1)
                             clobwriter2.write(cbuffer2, 0, nread2);
                        //clobwriter2.flush();
                        clobwriter2.close();
                   System.out.println("done");
                   dbconnbean.closeConnection();
              catch(Exception e)
                   System.out.println("Error: " + e);
    My error is java.sql.SQLException fetch out of sequence. I don't have an Idea on what seems to be the problem. Please help.. Thank you very much. ^_^

    Hi,
    Print the whole stack trace. It will tell you the line which causes the error. How you use clob and blob in oracle is also version dependent. Try to google for
    oracle "your version" java clob example.
    /Kaj

  • Insert Text in a PDF Document

    I am trying to edit text (insert text) in a pdf document using Adobe 9 Pro.  When I click on Advanced Editing, touch up text tool.  I select a box around the text and begin to type, nothing appears the cursor moves but nothing is typed.  I need immediate help .

    Editing text and Adding text require different tools.
    The Touch up text tool would be used to modify; add, modify or delete within a line of existing text.
    To add text to an open area, the Typewriter tool would be necessary.
    Don't expect full editing abilities.

Maybe you are looking for

  • RuntimeException in Message-Mapping transformatio

    Hi all, My XI server is successfully picking up a comma separated file from an FTP server and generating the corresponding XML: <?xml version="1.0" encoding="utf-8" ?> <ns:CondRec_MT xmlns:ns="http://namespace-ConditionRecords"> <Recordset> <Conditio

  • Airport express Connection Problem

    The airport worked fine at my home but i brought it to college and the airport says its connected but i get no signal. How do i fix the internet through the airport? My normal ethernet connection is working, just not the airport

  • In need to install classic on a g4 running with 10.3.5 instalationdisc from

    i just got a dual 533 hz g4 and i want to upgrade it for my studio i got a powerlogix upgrade {dual 1.2 with L4 cache] the hardware instalation is no problem but i need to upgrade the boot rom to version4.2.8 which i was told by powerlogix can only b

  • Short question about the nano controls

    Hi. I'm probably going to buy a 4Gb nano today, but first I'd like to ask a short question about the << >> buttons on the click wheel. I read in a forum that the << & >> buttons are actually 'skip' buttons (only used to play the previous or next song

  • How to download lion in macbook air 2011

    hi i can not lion in macbook air new 2011 because ask apple id !!! plz help