Insert HTML.Tag attributes?

Hey,
How would I insert html attributes? I am making a HTML Editor.
The following are some valid java html attributes. How would I insert it properly?
HTML.Tag.P, HTML.Tag.BLOCKQUOTE, HTML.Tag.CENTER,
HTML.Tag.CITE, HTML.Tag.CODE, HTML.Tag.H1, HTML.Tag.H2,
HTML.Tag.H3, HTML.Tag.H4, HTML.Tag.H5, HTML.Tag.H6,
HTML.Tag.PRE
Like for example, to make text bold, you would do
MutableAttributeSet attr = new SimpleAttributeSet();
StyleConstants.setBold(attr, true);
textpane.setCharacterAttributes(attr,false);
Is there similar code like the one above to add HTML.Tags like the ones I listed above in my post?
Thanks in advance

Hi,
sorry about the delay, couldn't find this thread last night.
Useful docs:
http://java.sun.com/products/jfc/tsc/articles/text/element_interface/index.html
and
http://java.sun.com/products/jfc/tsc/articles/text/attributes/
Those methods are in javax.swing.text.html.HTMLDocument and take the form insertBeforeStart(Element, String). As I said yesterday, as soon as you have text then the caret is in a character Element and a Paragraph element. So for e.g. if you're in a P element and you want to create an H1 element, how do you do it? If the user clicks your H1 button then you create an empty heading, easy enough. But if they have some text selected then you have a choice. You could just create an empty H1 or you could assume that they have typed the H1 content and have highlighted it so that it becomes an H1. You then have to change the existing element so that is no longer has the (now H1) text in it.
That's where the other two methods (setInnerHTML and setOuterHTML) come into play.
The other problemette that I'm working on is reseting text back to normal after it has been formatted.
Suppose you have a P paragraph. The user highlights a single word, clicks Bold. That's easy. Then they decide that they don't want it bold, so they click the Normal button. Taking bold off is easy, but should you. What if the paragraph element was actually an H1 element. If you turn bold off now then that word no longer matches the H1 style.
You could check at the caret position just before the start of the element that the user has selected and see what the style is there. BUt then waht if the user has the word before perhaps underlined. Again it's unreliable.
Also I'm finding then when I remove the bold formatting that the element isn't being reabsorbed into it's parent. In a paragraph if I go through and make each word formatted (B, i, u) and then switch the formatting off word at a time I end up with each word as an element.
Still working on these, so I'll post a solution when I have one.
regards
sjl

Similar Messages

  • How do I modify a Html tag attribute?

    Hi.
    I tryed to modify the witdth and height attributes of <applet> tag but I have not obtained it. I run this:
    import java.io.*;
    import javax.swing.text.*;
    import javax.swing.text.html.*;
    import javax.swing.text.html.parser.*;
    class OtraPrueba{
         public static void main(String[] args){
              String infile = "c:\\Page1.htm";
              String outfile = "c:\\outPage1.htm";
              String applethtml = "<applet code=\"class1.class\" codebase=\"v_10\" width=\"100\" height=\"100\" archive=\"class1.zip\"";
              Reader r;
              Writer w;
              HTMLDocument htmldoc;
              HTMLEditorKit kit = new HTMLEditorKit();
              HTMLEditorKit.ParserCallback callback =          
                   new HTMLEditorKit.ParserCallback(){
                        public void handleText(char[] data, int pos){
                             for(int i=0;i<data.length;i++)
                                  System.out.println ("data[" + i + "]" + data);
                        public void handleStartTag(HTML.Tag t, MutableAttributeSet a, int pos){
         System.out.println ("handleStartTag " + t);
         if (t == HTML.Tag.APPLET){
              a.removeAttribute(HTML.Attribute.WIDTH);
              a.addAttribute(HTML.Attribute.WIDTH, "100");
              try{
                   r = new FileReader(infile);
                   w = new FileWriter(outfile);
                   System.out.println ("antes del parser");
                   new ParserDelegator().parse(r, callback, false);               
    Can you help me?
    Thanks.

    Hello uhilger.
    I do it what you tell me last week but I get a NullPointerException at write the document extends HTMLDocument. It seems tries to write a empty tag. this is the exception text:
    _______________________exception text_____________________________
    java.lang.NullPointerException
    at javax.swing.text.AbstractWriter.write(AbstractWriter.java:489)
    at javax.swing.text.html.HTMLWriter.emptyTag(HTMLWriter.java:315)
    at javax.swing.text.html.HTMLWriter.write(HTMLWriter.java:187)
    at javax.swing.text.html.HTMLEditorKit.write(HTMLEditorKit.java:289)
    at Editor.setAppletAttributes(Editor.java:1017)
    at Editor.saveMenuItemActionPerformed(Editor.java:535)
    at Editor.access$13(Editor.java:24)
    at Editor$14.actionPerformed(Editor.java:421)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:17
    67)
    at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Abstra
    ctButton.java:1820)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel
    .java:419)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:257
    at javax.swing.AbstractButton.doClick(AbstractButton.java:289)
    at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1
    092)
    at javax.swing.plaf.basic.BasicMenuItemUI$MouseInputHandler.mouseRelease
    d(BasicMenuItemUI.java:932)
    at java.awt.Component.processMouseEvent(Component.java:5021)
    at java.awt.Component.processEvent(Component.java:4818)
    at java.awt.Container.processEvent(Container.java:1380)
    at java.awt.Component.dispatchEventImpl(Component.java:3526)
    at java.awt.Container.dispatchEventImpl(Container.java:1437)
    at java.awt.Component.dispatchEvent(Component.java:3367)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3214
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:2929)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:2859)
    at java.awt.Container.dispatchEventImpl(Container.java:1423)
    at java.awt.Window.dispatchEventImpl(Window.java:1566)
    at java.awt.Component.dispatchEvent(Component.java:3367)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:445)
    at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh
    read.java:190)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
    ad.java:144)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:130)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:98)
    ___________________end_exception text_____________________________
    I make a subclass of HTMLDocument with name EditableHTMLDocument :
    import javax.swing.event.*;
    import javax.swing.text.*;
    import javax.swing.text.html.HTMLDocument;
    class EditableHTMLDocument extends HTMLDocument{
         public void addAttributes(Element e, AttributeSet a) {
              if ((e != null) && (a != null)) {
                   try {
                        writeLock();
                        System.out.println("SHTMLDocument addAttributes e=" + e);
                        System.out.println("SHTMLDocument addAttributes a=" + a);
                        int start = e.getStartOffset();
                        javax.swing.text.AbstractDocument.DefaultDocumentEvent changes =
                        new javax.swing.text.AbstractDocument.DefaultDocumentEvent(start, e.getEndOffset() - start,
                             DocumentEvent.EventType.CHANGE);
                        AttributeSet sCopy = a.copyAttributes();
                        MutableAttributeSet attr = (MutableAttributeSet) e.getAttributes();
                        changes.addEdit(new AttributeUndoableEdit(e, sCopy, false));
                        attr.addAttributes(a);
                        changes.end();
                        fireChangedUpdate(changes);
                        fireUndoableEditUpdate(new UndoableEditEvent(this, changes));
                   }finally {
                        writeUnlock();
    And this is the method of program main class than call you addAttributes method:
         private void setAppletAttributes(){
              BufferedReader br;
              BufferedWriter bw;
              HTMLDocument htmlDoc;
              EditableHTMLDocument editHtmlDoc;
              HTMLEditorKit kit = new HTMLEditorKit();
              try{          
                   br = new BufferedReader( new FileReader( jTxtHtmlFile.getText() ) );
                   //htmlDoc = (HTMLDocument)kit.createDefaultDocument ();
                   editHtmlDoc = new EditableHTMLDocument();
                   kit.read (br, editHtmlDoc, 0);
                   br.close ();
                   javax.swing.text.Element rootElem = editHtmlDoc.getDefaultRootElement ();
                   javax.swing.text.Element elem =
                        editHtmlDoc.getElement (rootElem, HTML.Attribute.CODEBASE, jTxtCodebase.getText ());
                   SimpleAttributeSet sas = new SimpleAttributeSet();
                   sas.addAttribute ( HTML.Attribute.CODE, jTxtCode.getText () );
                   sas.addAttribute ( HTML.Attribute.CODEBASE, jTxtCodebase.getText () );
                   sas.addAttribute ( HTML.Attribute.ARCHIVE, jTxtArchive.getText () );
                   sas.addAttribute ( HTML.Attribute.WIDTH, jTxtAnchoApplet.getText () );
                   sas.addAttribute ( HTML.Attribute.HEIGHT, jTxtAltoApplet.getText () );
                   editHtmlDoc.addAttributes (elem, sas);
                   editHtmlDoc.dump (System.out);
                   bw = new BufferedWriter( new FileWriter( jTxtHtmlFile.getText() ) );
                   System.out.println ("length " + editHtmlDoc.getLength ());
                   kit.write (bw, editHtmlDoc, 0, editHtmlDoc.getLength ());
                   bw.flush ();
                   bw.close ();
              }catch(BadLocationException ble){
                   System.out.println ("BadLocationException " + ble.getMessage());     
    }catch(FileNotFoundException fnfe){
                   System.out.println ("FileNotFoundException " + fnfe.getMessage());     
              }catch(IOException ioe){
                   System.out.println ("IOException " + ioe.getMessage());
    Which you think that it is the problem?
    Thank you.
    Sergio Mart�n
    I visited your great page and download your SimplyHTML. I'll probe later.

  • Inserting HTML tag for character style

    I want to be able to use the <DEL> HTML tag around some text:
    <p>Regular Price <del>$395</del>  Today $95</p>
    So, it should look like this:
    Regular Price $395 Today $95
    This works reliably in Dreamweaver (both preview and in various browsers). It also works on this forum page! But I can't get it to work in Muse.
    Here is my test site:
    http://musetest-dec152012.businesscatalyst.com/index.html
    I followed the instructions here:
    http://forums.adobe.com/message/4819276#4819276
    This shows how to add a scroll box using HTML. That works on the test site. I then modified the contents to add <DEL> to the second word and it isn't shown. [I also added <STRONG> to the sixth word and it doesn't show either.]
    I followed the instructions here:
    http://forums.adobe.com/message/4399108#4399108
    This shows how to use a character style. The <MARK> style seems to work, but the <STRONG> style doesn't show up in the browser. Any rate, there is no way I can find to add my own tag and the <DEL> tag is not one of those in the pull down list.

    Iain --
    Muse overrides the default styling for the 'del' and 'ins' tags. If you want to use these tags in custom HTML, and have styling applied to them, you'll have to specify the styling you want with inline CSS, like so:
    <p>Regular Price <del style="text-decoration: line-through">$395</del>  Today $95</p>

  • Issue for email notification if insert html tag in question name

    I created discussion with name "Search highlight box issue in <textarea>" and receive the following email notice:
    You may need to add shielding tags in the title of the topic?

    In your XSL. I didn't find any Xpath expression to print values for these columns in table
    Transaction ID
    Transaction Type
    DateTime
    Status
    Code
    Message
    thanks,
    Satish
    http://soadiscovery.blogspot.com

  • Insert HTML tag, embedded code from YOUTUBE video place into my movie pg

    Okay, so I need to do 2 things actually, one is be able to copy and past the embedded code from a youtube video then place it into my movie page on my site... I was able to copy and paste the embedded code, drag n drop the HTML icon from iWEB onto the movie pg then paste in the embedded code
    the video shows up after adjusting the size appropriately but when I press the play button nothing happens?
    Also need to take the video from youtube and adjust it by changing a few things... how do I drag it into my imovie ?? or how do I go about editing the video?
    any help is much appreciated
    S

    The video will not play in iWeb itself - you need to publish it first because you have the code the and snippet within iWeb. If you want to check that it works, just publish to a local folder from iWeb to test it.
    You need to alter the code directly, so simply click on the html snippet and alter the code that you entered.

  • How to insert Html tag

    I want to send pics but via HTML through Photobucket. I have the code, drop it in the email but no picture? Any help is appreciated. thanks

    Best to just send the URL of the Photobucket page. If you want the image inlaid in your message, that usually only works if you put it in as an attachment, and the recipient has a mail client that supports Mail's attachment formatting.

  • Help needed in adding effects of certain HTML tags in Flex spark Richtext

    I want to apply the effects of the following HTML tags/ attributes, in my HTML text rendered in Flex Spark Richtext Component.
    Superscript - <sup>
    Subscript - <sub>
    Blockquotes - <blockquotes>
    Ordered Lists - <ol><li>
    Unordered List - <ul><li>
    Horizontal Rule - <hr>
    Direction Attribute for <p> - <p dir="rtl">Hello</p>
    Background Color for <font>
    I have observed that the above tags have no effect in RichText. Is this a limitation?
    Any solutions, tweaks and tricks will be appreciated...
    Thanks,
    Mangirish

    check this out . this should be able to answer you question.
    http://livedocs.adobe.com/flex/3/html/help.html?content=textcontrols_04.html
    Miguel

  • HTML Tags within Javascript Errors

    Hi,
    Is there a way to insert html tags (<b>Bold Text Here</b>), inside a javascript string in the <script> tag, without any Validation errors? I read to put a backslash at the beginning of each html tags to prevent the string from being parsed as markup (<\b>Bold Text Here<\/b>). Errors goes away, but bold texts too !
    Anyone can help me on this one ... I'm not a javascript Guru ...
    Thanks !

    All wrong... Correct string notation always requires single or double quotation marks:
    "\b this is a string"
    \b this is garbage
    Additionally, whan you escape characvters, each one must be escvaped separately:
    \b ... \/\b
    Mylenium

  • Popup with html tags

    Hi,
    Can anyone help me to write popup so I can insert html tag to make popup beautiful? Currently, I am using below code
    app.alert with cMsg
    cMsg do not support html tag. Any advise?
    Thanks

    Have you looked at the Acrobat JS API Reference for the Dialog object and and the app.execDialog documentation and examples?
    Have you looked at the Windjack Solutions and the examples for the AcroDialog product?
    There are more formatting options than the app.alert method and far less then HTML.
    Since we do not fully know exactly what formatting features you think you want, we can not fully answer your questions.
    If you do not find a formatting option that you want, you might try a button with an image of the text you want displayed.
    Have you read my response to your duplicate question.

  • Insert html-code at row level (td-tag)

    Hello,
    to control the layout of a tabular form, it would be advantageous to be able to insert html-code at row level (within the td-tag) of the region table, e.g. enabling us to set a class attribute: <tr class="strut">
    I don't see a possibility to do this within a region containing numerous elements.
    Thanks in advance for any hint.
    Thomas

    Thomas,
    Do you need to control each row independently of other rows? If so, you would need to have a look at using collections instead of the Tabular Form. APEX collections let you build your own custom 'tabular form' and you should be able to control each row individually.
    If, however, all you want to be able to do is apply a format to each row, this can be done in the template.
    Cheers,
    Colin

  • Why there is a difference in a "class" attribute value of html tag when viewed in "Page Source" and using "Inspector", I am refering to new Microsoft site?

    While inspecting the new Microsoft site source, I observed that the "class" attribute value of the "html" tag when seen in Page Source the value given by Tools/Web Developer/Inspect tool. Value with the tool indicates class="en-in js no-flexbox canvas no-touch backgroundsize cssanimations csstransforms csstransforms3d csstransitions fontface video audio svg inlinesvg" while that is given in Page Source is class="en-us no-js"
    The question is why different values are shown?

    Inspector is showing you the source after it's been modified by Javascript and such.
    To see the same thing in the source viewer, press '''Ctrl+A''' to select everything on the page, then right-click the selection and choose '''View Selection Source'''.

  • BC won't allow me to insert code (scripts) between the /body and the /html tags.

    Hi guys,
    So I have this weird problem. I'm trying to insert some codes between the </body> and the </html> tags in the page templates. It's saving it. But if you check the page, the code is showing before the </body>, not after. Here's the code that I'm trying to insert.
    <script src="http://i.simpli.fi/dpx.js?cid=1534&action=100&segment=198566&m=1"></script>
    I have also tried adding this code by downloading the templates through ftp, adding the code, then uploading it to the server. Same thing. I even added type="text/javascript" in the code. Still no go. BC wouldn't insert it between </body> and </html>. Any ideas guys?
    - Jeff

    So an update.
    I was told by Adobe chat support to try adding the script after the body via javascript.
    So I added this before </head>
    <script type="text/javascript">
    var script = document.createElement('script');
    script.src = '//i.simpli.fi/dpx.js?cid=1534&action=100&segment=198566&m=1';
    script.type = 'text/javascript';
    $("html").append(script);
    </script>
    Still not working. Any ideas guys?

  • JSF tags within normal HTML tags (jsfc attribute)

    Hi all,
    I was just browsing some JSF and Acegi information and I found the following tutorial:
    http://www.javakaffee.de/blog/2006/07/04/jsfacegi-authentication-with-a-backing-bean/
    In it, the author uses regular html tags but with attributes that allow JSF functionality.
    <input jsfc="h:inputText" id="inputUsername" value="#{authenticationController.username}" />I have never seen JSF done like this, could anyone inform me as to what is the jsfc property is?
    Thanks!
    Illu

    Ah, I found out my query. It's a feature in Facelets I believe. The link below has the info.
    Cheers,
    Illu
    http://www.jsftoolbox.com/documentation/facelets/06-CodeView/jsfc-feature.jsf

  • Way to remove HTML tags from a page-scoped attribute using JSTL?

    Hi,
    I'm using JSTL 1.2 with Tomcat 6.0.26. Does anyone know of a way to remove HTML tags from a page attribute, "${myExpr}". I would prefer a solution that uses JSTL only, but ultimately whatever gets the job done is fine with me.
    Thanks, - Dave

    I'm sorry, I don't understand your requirement. What do you mean by "remove HTML tags from a page attribute"?
    If you are dealing with a value of an attribute, it is most likely a String, and should be treated as such. The best approach would probably be java coding.

  • How to insert row in usercreat table(useing HTML tags)in jtextPane

    hi all
    i creat userdefined table in JTextPane like this
    tableBody.toString() -- iam passeing table tags
    htmlKit.insertHTML(htmlDoc, caretPos, tableBody.toString(), 0, 0, HTML.Tag.TABLE);
    i want to insert a row in table.. i did like this
    htmlKit.insertHTML(htmlDoc, caretPos, sRow.toString(), 0, 0, HTML.Tag.TR); it working..
    but it inserting in current location.. i want to insert ending of table...
    pls help me

    Hi,
    Follow the below logic,
    PROCESS BEFORE OUTPUT.
      MODULE STATUS_0001.
      MODULE POPULATE_TABLE_CONTROL. --> Get the data from table store in 
                                                                          ITAB
      LOOP AT GT_CTRL_LP_D516 INTO GS_WA_CTRL_LP_D516
           WITH CONTROL CTRL_LP_D516
           CURSOR CTRL_LP_D516-CURRENT_LINE.
      The following module moves data to control
        MODULE MOVE_TO_CONTROL.--> Move data from ITAB to table control
      ENDLOOP.
    PROCESS AFTER INPUT.
      LOOP AT GT_CTRL_LP_D516.
      ENDLOOP.
      MODULE EXIT AT EXIT-COMMAND.
      MODULE USER_COMMAND_0001.  --> Here you have to take out the values from table control and update database table
    Reward points if helpful.
    Thanks and regards,
    Mallareddy Rayapureddy,
    Munich, Germany.

Maybe you are looking for

  • OSX Mountain Lion "Messages" will not let me sign in...

    I cannot for the life of me get messages to work on the new OSX mountain lion.  I keep getting this alert when trying to sign in: "COULD NOT SIGN INTO iMESSAGE. The server encountered an error processing registration.  Please try again later." Any id

  • URL interaction not working in Catalyst CS5

    I am using Flash Catalyst to create some tabbed navigation images. All the functions work perfectly except for one tab that is suppose to link to a product page from my company's website. I have copied the exact URL into the interaction pull-down in

  • Phone doesn't work

    Just installed the new modem you say I have to have.  Went through the activate scenario and now my phone doesn't work....no dial tone, no nothing.  How will you fix that?   And, it's the only phone I have!!!

  • How to track history on one field

    Hi All, I have a table that i created in OWB, but now i have a requirement wherein they want me to add a new field and TRACK history on only that particular field. For example if any changes take place it should keep the old records as well. Any idea

  • ILife 08--Can I install applications individually?

    I have a PowerBook G4 with OS X v10.4.10. I understand that iMovie 08 will not work with 10.4, but everything else will. Is it possible to keep iMovie 06 and install 08 for the other applications? I want to make a website and it sounds like iWeb 08 m