Insert HTML into HTMLDocument

hello
i' have a problem using JTextPane. I want to select some text, and add some HTML tags around. For example, "Jeremie" is written ... i select all the text, i press the button and i want
that the HTML code generated is "<font class="toto">Jeremie</font>"
please help
jeremie

Yeah.. but. Where do you want the source code to be displayed ? Do you have a source code pane or something like that, or you just want HTML attributes to be applied to you text ?
Il give you some random examples of HTML manipulation.. but I don't clearly see what you want to do :
//set the appropriate EditorKit for JTextPane by determining its content type
JTextPane tpa = new JTextPane();
tpa.setContentType("text/html");
//get a reference to the tpaDefault document
HTMLDocument htmDoc = (HTMLDocument) tpa.getDocument();
//get a referene to HTMLEditorKit
HTLMEditorKit htmKit = (HTMLEditorKit) tpa.getEditorKit();
//Get selected text from JTextPane
String strSelText = JTextPane.getSelectedText();
//Get selection start and end positions
int intStartPos = JTextPane.getSelectionStart();
int intEndPos = JTextPane.getSelectionEnd();
//Calculate selection length
int intSelLength = intEndPos - intStartPos;
//Remove selection from HTMLDocument
htmDoc.remove(intStartPos, intSelLength);
//HTML String to insert
String strToInsert = "<font face="Verdana" size="3" color="red">" + strSelText + "</font>";
//Insert new formated HTML content using HTMLEditorKit
htmKit.insertHTML(htmDoc,strToInsert,intStartPos, 0,0, HTML.Tag.FONT);  That's more or less how it works.
Hope it helps,
Diego

Similar Messages

  • Inserting HTML into JTextPane

    Hi,
    I am trying to insert HTML into JTextPane.
    I am using the following code for the same.
    JTextPane jedit = new JTextPane();       
    jedit.setContentType("text/html");
            HTMLDocument doc = (HTMLDocument)jedit.getDocument();
            String text = "<a href=\"???\">hyperlink</a>asd<a href=\"???\">hyperlink123</a>";
            HTMLEditorKit editorKit = (HTMLEditorKit)jedit.getEditorKit();
            editorKit.insertHTML(doc, doc.getLength(), text, 0, 0, null);
            doc.insertString(doc.getLength(),"Hi testing",null);
            text = "<a href=\"???\">hyperlink123</a>";The problem is that the HTML gets inserted into new line. I do not want the new line.
    I know there is an API like insertBeforeEnd(...) but do not know how to use that.
    Any help for the above problem will be of great use.
    Thanks.

    look I have got the answer ... I guess this would be the root cause of the problem of new line.
    when ever you want the text to be inserted
    -at new line provide the last argument  of HTMLDocument.insertHTML as null
    - at same line provide the last argument as the HTML tag you are inserting into the JtextPane's document.thats it !!!
    ENJOY :-)

  • 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 HTML into a table?

    I am trying to find an easier method of inserting html code into a column of type varchar2. I have to insert 100's of lines of html into a table weekly and the inserts keep failing because of special charecters within the html code itself. I have written scripts using UTL_FILE functions but this is very tedious to do weekly. Is there a better method to accomplish inserting html?

    try this.
    Hi,
    procedure start_import (p_filename in varchar2)
    is
    v_lob clob;
    v_offset number := 1;
    v_file bfile := bfilename('IMPORT',p_filename);
    v_lob_length number;
    begin
    -- File open
    dbms_lob.fileopen(v_file);
    -- get file length
    v_lob_length := dbms_lob.getlength(v_file);
    -- Create temp LOB (CACHED)
    dbms_lob.createtemporary(v_lob,TRUE);
    -- fill Temp Lob with filecontent
    dbms_lob.loadfromfile(v_lob,v_file,v_lob_length);
    -- Close file
    dbms_lob.fileclose(v_file);
    So, now you have the Filecontent in your temp LOB.
    For more info. about LOB, read Oracle Documentation.
    Hope this helps,
    Kalpen
    <BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by Troy Johnson ([email protected]):
    I am trying to find an easier method of inserting html code into a column of type varchar2. I have to insert 100's of lines of html into a table weekly and the inserts keep failing because of special charecters within the html code itself. I have written scripts using UTL_FILE functions but this is very tedious to do weekly. Is there a better method to accomplish inserting html?<HR></BLOCKQUOTE>
    null

  • Inserting html into a composition in muse

    Hi, I am trying to insert some html into a composition in Muse.  I would like to have a clickable button trigger, and then a kind of overlay opens up with an interactive calculator inside.  I have the html for the calculator, the problem is no matter how I try to insert it into Muse, the calculator either disappears (as well as the trigger) for some reason, or the calculator stays on the page the entire time, losing the whole clickable effect.
    Can someone tell me the best way to do this?

    Hello,
    Which Composition are you trying to Use ? Blank,Featured News, Lightbox Display, Presentation or Tooltip ?
    Also Make Sure to drag and drop the inserted HTML window over the target (Border of target gets activated once you move it over), Hopefully this will work.
    I created the same using Tooltip composition and its working fine. Please take a look at the link.
    Home
    If it do not work then please share the calculator HTML  code that you are inserting so that I can do some test at my end.
    Regards
    Vivek

  • Insert html into styled document

    Hi,
    I would like to insert html content into a JEditorPane that uses a StyledDocument and DefaultStyledEditorKit. I do not want to use the HtmlEditorKit for some reasons though that might change later. Now, I want to insert ElementSpec objects into my styled document and the only way seems to be doc.insert(o, espec) where espec is of type ElementSpec[]. I would like to insert my ElementSpecs one by one if possible.
    Can someone tell me how I can do this.
    Cheers,
    Omprakash.V

    Hi,
    I was referring to DefaultEditorKit in the above post when I said DefaultStyledEditorKit.
    Cheers,
    Omprakash.V

  • Inserting HTML into a web page

    On a previous thread I asked how to insert ones own code into a page created in iWeb.Some kind person told me how to do it,namely: find the html page in iMac on my hard drive,in TextEdit insert the code that I want and click Save.It all worked fine. However when I go back into my web page in iWeb and make a change followed by upload, the code that I inserted in TextEditor is wiped.Is there any way that I can insert my own code into a web page and not get it wiped when I make other changes in iWeb and upload to the server? Thanks in advance

    Nope, this is how it works. If you make a change to a page like this post-publishing, and later re-publish, you have to make the html changes again! Set up a Find/Replace command in MassReplaceIt and you can do this very quickly. You can save your queries so you can make all of your changes with one click the next time you save.
    Download here:
    http://www.hexmonkeysoftware.com

  • Inserted HTML does NOT push content when resized

    Hi,
    we are building a website for a hotel and are bound to include their channel manager module into the site. In order to do that, you have to follow these steps:
    1. Paste JavaScript code into the head section to load the module.
    2. Place a short line of code with "insert HTML" into the site where the module should appear and that's it.
    The module is generated by a server-side script from the channel manager's server and pasted into an iFrame that is also generated by this very script. The thing is: It resizes the height of the iFrame depending on the displayed content in the iFrame. So we start with 301 px height when we call the page and start the search for free rooms. The results are displayed on a 1400 px iFrame, which resizes properly when showing the results.
    THE PROBLEM: The footers stays put and the iFrame runs behind it and off the display port. There is also no scrollbar showing up allowing me to scroll to the bottom of the iFrame.
    We got three layers:
    3. Top Layer (Containing top navigation and footer, both defined in a master page that is applied to the content page)
    2. Content Layer (Containing the inserted HTML with the generated iFrame)
    1. Background Layer (Well, it contains background elements)
    WE NEED: The footer to be pushed by the ever resizing iFrame and get a scrollbar when neccessary due to iFrame height.
    What are we doing wrong?

    Thank you for your suggestions, although I don't think they will fix the problem.
    We cannot alter the server script in any way, since it is located on the channel manager's server and is just called with a customer id to show our client's hotel related data. They resize the iFrame using an inline height style tag. This causes the page to not recognize the size change and not even showing a scrollbar at all, when the iFrame exceeds the view port.
    We already put a div around the JS-call which expands with the iFrame as expected.
    <div id="u1218"><!-- custom html -->
    <div>
    <script language="javascript" type="text/javascript">
    function();
    </script>
    </div>
    </div>
    This results in an iFrame inserted after the script tag, the div around the script expands correctly. We already removed any master page objects, created a blank new master page to define header and footer areas and pasted our menu and footer directly into the page of question on the same layer as the inserted html box went. So for our understanding the expanding div around the script should push the footer on this page to whereever it ends. It just doesn't. Also we do not get any scrollbar, although the iFrame clearly gets larger than the viewport area and the page just doesn't recognize it.

  • Ability to insert HTML code snippets not available

    Supposedly I can insert HTML into a file in Contribute but
    that option is grayed-out and can't be used. Does anyone know why
    that capability would not be functioning. I have the most recent
    version of Contribute and use it on a PC

    In the main menu go to:
    1. Edit, Administer Websites
    2. Users and Roles, click Edit Role Settings
    3. go to Editing
    4. check 'Allow HTML snippets insertion...' (last option)

  • Text disappears to the right and below inserted html, any ideas?

    When I insert html into the page, the text I have to the right and below disappear from the page. If I move the html below both sets of text everything appears fine. Any ideas?

    Hello,
    Could you please provide me the link to your website (if you have uploaded it).
    Else could you please paste the html code (that you are placing on the page) here so that we can have a look at it.
    Regards,
    Sachin

  • IChat inserts HTML for ICQ users

    When I chat with other ICQ users, iChat inserts HTML into my dialogue containing formatting for the text. This only happens when the other person doesn't have iChat but a different chat client.
    Is there an option to turn this kind of unhelpful text styling off for my outgoing messages?
    iBook G4   Mac OS X (10.4.5)  

    Hi Simon,
    As far as I can tell iChat sends the HTML stuff to produce the Bubble inforamtion at the other end.
    Obviously AIM ignores it and ICQ does not.
    I am not sure if switching to Text only actually completely solves it completely but it is an option.
    There is no halfway setting.
    Thanks for the points.
    10:45 PM Sunday; March 19, 2006

  • How to style a custom form that's been inserted as HTML into Muse

    Apologies in advance if something similar already exists, and as a print-based designer I'm likely to use incorrect terminology.
    I've created a basic website that requires a custom form. I've created this form using dreamweaver as it requires a dropdown and a check box. The unstyled html from DW I then insert into Muse via the 'Insert HTML' function, on a page called 'booking form'
    To style it I did the following...
    - Opened the form I created back in DW and added classes to the labels .formname, and added a class to some terms and conditions that sits somewhere in the form and called that .formsubtext
    - Copied all of this code and inserted it back into Muse via Insert HTML
    - The form shows up unstyled as expected
    - I export the site as HTML
    - Go into the exported folder into the CSS, and into the corresponding css file booking-form.css
    - Added some custom CSS styling to reflect the font and colour I wanted to use
    - Re-uploaded those edited files
    - The result was that it rendered the class .formsubtext reflecting the terms and conditions as it should but not all the other labels
    Would someone be able to tell me a better way to style a custom form or point out what I've done wrong.
    Thanks!!!

    If you have structured your HTML markup for the form well using appropriate class and id names, then you can just add corresponding CSS using the <style> element in the "HTML for <head>" section in Page Properites > Metadata.
    You may also choose to add all the CSS in a separate file and add reference to that in the HTML for <head> section and then upload the CSS file in appropriate location after publish.
    Cheers,
    Vikas

  • Import(insert) formatted text(HTML) into document

    Hi guys, I have faceed with folowing problem:
    how to insert into text frame formatted text ?
    At Indesign desktop version this feature was able through pasting HTML from clippboard with appropriate settings of clippboard preferences. But at server version there is no such function.
    I have also invesigated XML import:  you can set up text and paragraph styles and map them with tags but this technique doesnt support nested styles for instance if you have <b><i>xxx</i></b> and appropriate styles "b" and "i" i will be applied to "xxx".
    So I need to insert html as it did clipboard pasting.
    Any thoughts ?

    Questions:
    1. What version of SQL Server are you using?
    2. Are you required to use a specific DTS package or do you simply need to import data from a file to a table?  You might also consider using the bcp utility or, if you are using 2005 or newer, integration services.
    3. Is the uploading of files and the import of data a manual process or is it automated?  Is there a user uploading one file at a time to your server or do you receive files in batches.  Can you describe the work flow?
    You might try the following if you are required to use DTS:
    1. Upload your text file with CFFILE, putting in the directory expected by your DTS package.
    2. Rename the file to the name required by your DTS package
    3. Use CFEXECUTE to run the DTS package by calling dtsrun at the command line.
    dtsrun
    http://msdn.microsoft.com/en-us/library/aa224467%28SQL.80%29.aspx
    bcp
    http://msdn.microsoft.com/en-us/library/aa174646%28SQL.80%29.aspx

  • Insert Animation into a website gadget that accepts HTML code or a URL

    I have opened up the HTML page and inserted the source code into the gadget. Once I open my website, the edge animate animation does not show. Is that the best way to insert my edge animate project into a website?
    Inserting it into a "Gadget Container" is the way I have to go about it. Just unsure what code I need to insert into this Container.

    I have opened up the HTML page and inserted the source code into the gadget. Once I open my website, the edge animate animation does not show. Is that the best way to insert my edge animate project into a website?
    Inserting it into a "Gadget Container" is the way I have to go about it. Just unsure what code I need to insert into this Container.

  • Insert Html 5 content into web page

    With Flash being phased out, how can you insert HTML 5 content into existing web pages?
    I'm trying to figure it out but it's not working properly.

    You can easily load it into another page using an iFrame.

Maybe you are looking for