HTML editing with JEditorPane - HTMLEditorKit actions

I am trying to make a component that will allow the user to edit styled text, use some buttons to change text properties - font/color settings, allow him to insert tables and so on.
From reading through the Swing tutorial and searching around I came to a conclusion that JEditorPane(or JTextPane - I haven't chosen one yet) is the component I must use. I intend to use HTMLEditorKit with it. What worries me are some fields in HTMLEditorKit - some public static String members that are documented as action identifiers(like FONT_CHANGE_BIGGER, FONT_CHANGE_SMALLER...).
How to use those actions? I saw an example from O'Reilly 'Java Swing' book where they took the actions out of the editorPane's action map, but I could not find actions with names like above in the ActionMap of the JTextPane after I installed HTMLEditorKit /calling setEditorKit(new HTMLEditorKit())/.
I also want to know how to insert tables and stuff like this. I think I must use HTMLEditorKit.InsertHTMLTextAction class and pass it HTMLEditorKit.INSERT_TABLE_HTML, but I am not sure this is the way to go.
Can someone lead me to a good resource where I can better understand the details about using the actions of the HTMLEditorKit?
Thank you for your time
Mike

.

Similar Messages

  • Problem Printing html page with JEditorPane...

    Hello All,
    I Have a problem in printin html file with JEditorPane...
    My Html file contains a Table on it..
    Problem is that JEditorPane displays the html file correctly but
    it prints the file without print that Table..
    So pls help me...
    Thanx in advance,..
    Amit
    [email protected]

    I think you would know how to retrieve content of an HTML page using the URL object. Just in case.
    My apology if this short note doesn't help you at all.

  • Custom html tags with JEditorPane

    I'm trying, to use my own tags within html in the JEditorPane. An insert parses without exception but the html in the pane is missing the custom tags that I attempted to insert. I have tried to use the 'setPreservesUnknownTags' command on the html document, but it appears to have no affect. This is the code I have been trying to use:
    edtHTML.insertHTML(docHTML, 0, "<p><my:link id=\"12\">ABC</my:link></p>", 0, 0, HTML.Tag.P);
    I have also tried
    edtHTML.insertHTML(docHTML, 0, "<my:link id=\"12\">ABC</my:link>", 0, 0, new HTML.UnknownTag("my:link"));
    Can anyone help?
    Thanks

    I have no example for custom Tags but I found out that every tag is stored as an attribute.
    You can access the attributes if you use a JTextPane. There is a method (i don't know the name yet I will find out tomorrow in the office) which gives you the AttributeSet of each Character at the Carent position. All characters have an attribute "name" and the value of this attribute should be the name of the tag you've inserted.
    The only problem is that I had to read out every character so it's quit slow.
    If you could find a better solution please let me know ([email protected]).
    Thank you.
    J&ouml;rn

  • HTML Printing with JEditorPane table borders is missing...

    Hi,
    My application prints HTML reports that was rendered on a JEditorPane,
    actually the printing is working fine (almost)...
    After reading a lot of posts and the Printing API i've found a very god aproach to print HTML documents... the DocumentRenderer:
    http://www.fawcette.com/javapro/2002_12/online/print_kgauthier_12_10_02/
    I'm having a strange problem that I was unable to figure out by myself...
    Table borders and table background images never get printed...
    ex: <TABLE BORDER=1 ...
    <td background="image.gif" ...
    On the JEditorPane it shows just fine but, when the page is printed there's no border or table background pictures...
    Everything else is printed ok including images, small fonts, etc...
    Does anyone else had the same problem ?
    Thanks for any help

    The borders present an interesting problem created by the way the DocumentRenderer class finds for printable Views in the HTML. DocumentRenderer searches recursively down the tree of Views starting with the Document's root view looking for leaf views, those with no children. The DocumentRenderer only paints these smallest chunks of text to the printer graphics context. This usually works because leaf views do not usually contain anything paintable.
    The problem with borders is that they represent paintable areas of branch views, those with children. When we only print leaf views, these areas get ignored.
    I see two logical solotions to the problem:
    I. Change the code of the recursive printView method of Document Renderer to print any border that intersects with the current printable clip rectangle.
    II. A much more elegant solution would be to print any view, branch or leaf, that fits within the current printable area, and cease the recursion there. This would include the borders.
    It would also increase efficiency by terminating the recursive method earlier by painting larger chunks of the HTML. A strange problem pops up when I try this, however. When the size of the chunk to be printed gets too big, nothing is printed at all. In the article this is mentioned in the area of large images. "Lastly, large icons do not print. Java simply refuses to render them on the page. Small icons work quite well, however." The same holds true for any large View.
    I have not been able to quantify the exact size where this failure occurs, nor what is causing it. If anyone can tell me what causes this problem, it should be fairly easy, depenging on the cause of the problem, to rewrite the class to print borders and also does lots of other good stuff. I have already coded the new and improved printView method, but this size limitation has made it unworkable.
    Simply stated, if I can figure out why the class does not print large icons, the rest should be easy.
    Any suggestions would be appreciated.
    Thanks,
    Kei Gauthier

  • Display HTML Tables In JEditorPane

    Hi all,
    I am Editing an HTML Document in a JEditorPane.I've Noticed that The HTMLEditorKit has many flaws.
    I tried to fill them by registering my own tag actions for some tags. Now the new problem that I am facing is how an html table is displayed : The cellborders ares not visible. So i can see the content of the table, but not its borders. What should I do to make them show out ?
    thanx

    I had some problems with using HTML Tables with JEditorPane (it's really flaky). What I found was you have to be very specific when you create the table. Meaning, the cells have to be set using exact pixel sizes, not relative sizes or percentages. This is a pain, but if you do that then it should work.
    <table width=400 border=1 cellspacing=0 cellpadding=1> etc.......m

  • JEditorPane HTMLEditorkit Image align left

    Hi,
    I am developing a HTML Editor with JEditorPane and HTMLEditorKit. Apart from the many other difficulties, the HTMLEditorKit doesn't show a text next to an image correctly. I set an Image alignment to left and hopped, the text would be displayed text to it beginninge at the top. But it doesn't. Can anyone help.
    Christian

    Hi,
    I'm sorry, but this doesn't help me at all. To be more precisely, I want a text placed next to an image. A normal Browser does is when you say something like <img align="left" ...> and just place your text behind this tag. It looks like this:
    %%%%%%%%%% My Text My Text My Text My Text My Text My Text
    %%%%%%%%%% My Text My Text My Text My Text My Text My Text
    %%%IMAGE%%%% My Text My Text My Text My Text My Text My Text
    %%%%%%%%%% My Text My Text My Text My Text My Text My Text
    %%%%%%%%%% My Text My Text My Text My Text My Text My Text
    The Problem with the JEditorpane and the HTMLEditorKit is, that it shows up like this:
    %%%IMAGE%%%%
    %%%%%%%%%% My Text My Text My Text My Text My Text My Text
    My Text My Text My Text My Text My Text My Text
    My Text My Text My Text My Text My Text My Text
    My Text My Text My Text My Text My Text My Text
    My Text My Text My Text My Text My Text My Text
    If I put the alignment to top or something else, I can let it look like this:
    %%%%%%%%%% My Text My Text My Text My Text My Text My Text
    %%%IMAGE%%%%
    My Text My Text My Text My Text My Text My Text
    My Text My Text My Text My Text My Text My Text
    My Text My Text My Text My Text My Text My Text
    My Text My Text My Text My Text My Text My Text
    But annoyingly I let it show up like in any normal Internet Browser.
    Hope my problem is more clearly now and somebody can help me.
    Yours sincerely,
    Christian

  • JEditorPane/HTMLEditorKit displays weird html-table-borders

    Hi there,
    I am currently fighting with JEditorPane and its HTML functionality.
    I would like to create a table with padding:2 and border:1 - every browser displays that correctly (even HotJava the father of HTMLEditorKit's functionality), however JEditorPane paints the border really ugly adding a 1993-style 3D effect to my table :-/
    Any ideas how I could tell JEditorPane to just draw a single 1px line as table border?
    Thank you in advance, lg Clemens

    I guess you need to use a CSS file binded to you HTML doc,
    JEditorPane view = new JEditorPane("text/html","<p>empty</p>");
    StringBuffer l_sb = new StringBuffer();
    sb.append("<head>" +
    "<link rel=stylesheet href=&apos;mystyle.css&apos;>" +
    </head>");
    view.setText(sb.toString());
    then you can control the border using :
    body {
    background-color: #f0fff0;
    font-family: Arial;
    font-size: 12pt;
    table {
    border-width: 1px;
    border-style: solid;
    border-color: #000000;
    and NOT as the standard way (doesnt work)
    border: 1px solid #000000;
    Hope this help.

  • How can i edit a .html file with jdeveloper?

    hi
    when i use ibm websphere, i can edit a .html file visually.
    but when i use 9ideveloper, i can not do the same thing.
    i do not want to learn writing html code with notepad.
    who can help me?
    tell me how to deal with this problem.

    Hi,
    JDeveloper 9.0.3 and 9.0.4 don't have a WYSIWYG HTML editor. JDeveloper 9.0.5 that will be close to 9.0.4 has a WYSIWYG editor for both, HTML and JSP.
    Frank

  • Can't Edit Valid CSS/HTML page with DW

    I have a page that contains valid HTML and CSS but it is VERY
    hard to edit with DW-CS3. The formatting in design view looks
    nothing like the page when displayed in a browser. I can always
    edit the code directly via the code view but I have users that want
    to update the site using the design view. Maybe I don't have DW set
    up properly . Can someone take a look and let me know if this page
    can be edited? Will it require CSS changes ? Thanks in advance for
    any help.
    Here's a link to the page: www.nysga.org/indexnew.html

    Sure they do.
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    ==================
    "josie1one" <[email protected]> wrote in message
    news:fqk3pk$b8s$[email protected]..
    >> Here's some links to screenshots - in the top gif
    you'll notice that the
    >> LOGO doesn't even display.
    > To the best of my knowledge a background image will not
    display in design
    > view. Mine certainly don't.
    >
    > --
    > Jo
    >
    >
    >
    >
    > "tobgolflink" <[email protected]> wrote
    in message
    > news:fqk386$akv$[email protected]..
    >> Maybe I wasn't clear with my original message. The
    problem is that the
    >> design
    >> view doesn't format properly. I'll add some links to
    screenshots of what
    >> DW
    >> looks like when I try to edit the page. You can try
    it yourself. Save the
    >> page
    >> and the CSS locally and see what it looks like in
    DW.
    >> Here's some links to screenshots - in the top gif
    you'll notice that the
    >> LOGO
    >> doesn't even display.
    >> In the bottom gif you'll see the the right side
    navigation is on the
    >> left.
    >>
    http://www.nysga.org/top.gif
    >>
    http://www.nysga.org/bottom.gif
    >>
    >
    >

  • Problem viewing html with JEditorPane..

    The program will run, but it displays nothing but an empty pane. The program program also stars out very small in the top right hand corner of the screen so I have to resize it. What do I need to do to be able to view the HTML file?import javax.swing.*;
    import javax.swing.text.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.net.URL;
    import java.io.IOException;
    public class test_pane extends JFrame //implements ActionListener
    public test_pane()
    super("Note");
    //Create editor pane
    JEditorPane editPane = createEditorPane();
    JScrollPane escroll = new JScrollPane(editPane);
    escroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    escroll.setPreferredSize(new Dimension(500, 250));
    escroll.setMinimumSize(new Dimension(10,10));
    private JEditorPane createEditorPane()
    JEditorPane editPane = new JEditorPane();
    editPane.setEditable(false);
    String s = null;
    try {
    s = "file:"
    + System.getProperty("user.dir")
    + System.getProperty("file.separator")
    + "TextSamplerDemoHelp.html";
    URL helpURL = new URL(s);
    displayURL(helpURL, editPane);
    catch (Exception e)
    System.out.println("Couldn't create help URL: " + s);
    return editPane;
    private void displayURL(URL url, JEditorPane editPane)
    try {
    editPane.setPage(url);
    catch (IOException e)
    System.out.println("Attempted to read a bad URL: " + url);
    public static void main(String[] args)
    JFrame frame = new test_pane();
    //frame.setSize(600,500);
    frame.addWindowListener(new WindowAdapter()
    public void windowClosing(WindowEvent e)
    System.exit(0);
    frame.pack();
    frame.setVisible(true);

    Ok, I couldn't see where you add the scroll pane to the content pane of the frame and without a minimum size set somewhere the frame.pack() would shrink it completely. I recreated what you wrote and put the minor changes in there.
    Try this out:
    import javax.swing.*;
    import javax.swing.text.*;
    import javax.swing.text.html.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.net.URL;
    import java.io.IOException;
    public class Temp extends JFrame {
         BorderLayout borderLayout1 = new BorderLayout();
         JScrollPane jScrollPane1 = new JScrollPane();
         JEditorPane jEditorPane1 = new JEditorPane();
         HTMLEditorKit editorKit = new HTMLEditorKit();
         public Temp() {
              super("Note");
              this.getContentPane().setLayout(borderLayout1);
              jEditorPane1.setEditable(false);
    jEditorPane1.setEditorKit(editorKit);
              this.getContentPane().add(jScrollPane1, BorderLayout.CENTER);
              jScrollPane1.getViewport().add(jEditorPane1, null);
              String s = null;
              try {
                   s = "file:"
                   + System.getProperty("user.dir")
                   + System.getProperty("file.separator")
                   + "TextSamplerDemoHelp.html";
                   jEditorPane1.setPage(new URL(s));
              catch (Exception e) {
                   System.out.println("Couldn't create help URL: " + s);
         public static void main(String[] args) {
              JFrame frame = new Temp();
              frame.setSize(600,500);
              frame.addWindowListener(new WindowAdapter()
              public void windowClosing(WindowEvent e)
              System.exit(0);
              //frame.pack();
              frame.show();
    }

  • Working with JEditorPane to display HTML page

    iam loading html page into JEditorPane .
    how to get the html form data to validate
    give me soluation for this problem ...
    thanks ....
    karthi

    Search for occurences of <img> tags in the stream and replace its src="" contents by for example src="image?id=orginatingimagefilenameorso" and write kind of an ImageServlet mapped on "/image*" which streams the right images to the response.
    You may find this ImageServlet example useful: http://balusc.blogspot.com/2007/04/imageservlet.html
    After all, why are you streaming HTML files through a servlet instead of just linking to them? Aren't they public accessible or so? If this is the case, consider creating a virtual host on the application server so that you can just access those files through a simple plain vanilla URL.

  • Help Editing code from a published html file with flash detection enabled from flash

    hi guys ive publish a html file with flash detection enabled from flash
    heres the code from the publish html:
    <!-- saved from url=(0013)about:internet -->
    <html lang="en">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>main</title>
    <script language="javascript"> AC_FL_RunContent = 0; </script>
    <script language="javascript"> DetectFlashVer = 0; </script>
    <script src="AC_RunActiveContent.js" language="javascript"></script>
    <script language="JavaScript" type="text/javascript">
    <!--
    // Globals
    // Major version of Flash required
    var requiredMajorVersion = 9;
    // Minor version of Flash required
    var requiredMinorVersion = 0;
    // Revision of Flash required
    var requiredRevision = 45;
    // -->
    </script>
    </head>
    <body bgcolor="#ffffff">
    <!--url's used in the movie-->
    <!--text used in the movie-->
    <script language="JavaScript" type="text/javascript">
    <!--
    if (AC_FL_RunContent == 0 || DetectFlashVer == 0) {
         alert("This page requires AC_RunActiveContent.js.");
    } else {
         var hasRightVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
         if(hasRightVersion) {  // if we've detected an acceptable version
              // embed the flash movie
              AC_FL_RunContent(
                   'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,45,0',
                   'width', '800',
                   'height', '600',
                   'src', 'main',
                   'quality', 'high',
                   'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
                   'align', 'middle',
                   'play', 'true',
                   'loop', 'true',
                   'scale', 'showall',
                   'wmode', 'window',
                   'devicefont', 'false',
                   'id', 'main',
                   'bgcolor', '#ffffff',
                   'name', 'main',
                   'menu', 'true',
                   'allowScriptAccess','sameDomain',
                   'allowFullScreen','false',
                   'movie', 'main',
                   'salign', ''
                   ); //end AC code
         } else {  // flash is too old or we can't detect the plugin
              var alternateContent = 'Alternate HTML content should be placed here.'
                   + 'This content requires the Adobe Flash Player.'
                   + '<a href=http://www.macromedia.com/go/getflash/>Get Flash</a>';
              document.write(alternateContent);  // insert non-flash content
    // -->
    </script>
    <noscript>
         // Provide alternate content for browsers that do not support scripting
         // or for those that have scripting disabled.
           Alternate HTML content should be placed here. This content requires the Adobe Flash Player.
           <a href="http://www.macromedia.com/go/getflash/">Get Flash</a>
    </noscript>
    </body>
    </html>
    now since the default codes places my flash movie on upper left corner, ive made my own tables with the flash on it, how or where do i place this code to the upper codes?
    <table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <th valign="middle" scope="col"><table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <th height="600" bgcolor="#333333" scope="col"><script type="text/javascript">
    AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0','wid th','800','height','600','src','main','quality','high','pluginspage','http://www.adobe.com /shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','movie','main' ); //end AC code
    </script><noscript><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="800" height="600">
              <param name="movie" value="main.swf">
              <param name="quality" value="high">
              <embed src="main.swf" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="800" height="600"></embed>
            </object></noscript></th>
          </tr>
        </table></th>
      </tr>
      <tr>
        <td height="30" bgcolor="#990000"><table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <th scope="col"><table width="800" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <th scope="col"><div align="left" class="style1">Copyright 2009 St. Paul of the Cross Parish. All Rights reserved.</div></th>
                <th width="400" scope="col"><div align="right" class="style1">Usage outside our permissions guidelines requires our prior written consent.</div></th>
              </tr>
            </table></th>
          </tr>
        </table></td>
      </tr>
    </table>
    Tnx in advance!

    Hi
    Can you tell me which version of dreamweaver you are using (and flash pro, if you have it), as the code you provided has element of a number of different versions (e.g. your js flash files are reasonably new, but your flash inserted into the html body is old, but with the cs3 version of flash player indicated!). Also the detect flash file is no longer required.
    PZ

  • HTML encoding with JTextPane

    hello,
    I'm using JTexPane to edit rich text in my application.
    I set the editorkit with
    pane.setEditorKit(new HTMLEditorKit());
    and I create a new document for editing with
    pane.setDocument(pane.getEditorKit().createDefaultDocument());
    but when I enter text in the pane with accent like "j'ai mang� une pomme" , the method pane.getText() return my html document encoded with ISO-10646 aka Unicode where the "�" is &#233;
    I try to create the editorKit for the ContentType "text/html; charset=UTF-8" but it doesn't work.
    How can I change the encoding to UTF-8 ?
    Please help me ...

    hello,
    I know your problem (i'm french), but i don't know how to resolve it easily.
    you can get the HTML code by using
    pane.getText();and change manually characters...

  • How to go to anchor html link from external html page in JEditorPane

    Hi people,
    I've been trying to jump to an anchor link from an external html page in JEditorPane, and I cannot get it working, I'm sure it can be done somehow...
    The HTML page has a link like:
    Hello
    and this is loaded into JEditorPane ok.
    The HyperlinkListener implementation:
    public void hyperlinkUpdate( HyperlinkEvent e )
    try {
    if ( e.getEventType() == HyperlinkEvent.EventType.ACTIVATED )
    editorPane_.setPage( getClass().getResource(
    MyDialog.this.getBaseURL().concat( e.getURL().getFile().substring(
    e.getURL().getFile().lastIndexOf( "/" ) + 1 ) ) ) );
    if ( e.getURL().getRef() != null )
    editorPane_.scrollToReference( e.getURL().getRef() );
    else return;
    } catch ( IOException ioe ) { ioe.printStackTrace(); }
    This code loads the new html file ok, but it does not scroll to the anchor. The MyDialog.this.getBaseURL() just returns something like com.name.package, I construct the URL by using this base url and the name of the html file to open.
    ANy help, thanks

    he! I'm not alone in my desperation. Take a look at my problem:
    I've got a JEditorPane (not editable) inside a JFrame. The JEditorPane is loaded with the HTML text and all the links to anchors are working properly when I click on them.
    BUT
    If I try to go to an anchor from outside this JFrame I can see how the JEditorPane scrolls to the right anchor and suddenly it scrolls back to the place where the caret was located!!!
    The "funny thing" is that my code is working in jdk1.3.1 but this is happening in jdk1.4.2. Is it a bug?!?!?!
    How could I figure out what position I have to set the caret to for every anchor in order to get the scroll working correctly???
    My implementation of hyperlinkUpdate (working properly, here isn't the problem):
       jEditorPane.addHyperlinkListener(new HyperlinkListener() {
          public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
              MiEditorPane src = (MiEditorPane)e.getSource();
              src.goToAnchor(e.getDescription().substring(1));
        });My object jEditorPane is an instance of this class:
      class MiEditorPane extends JEditorPane {
        MiEditorPane() {
          super();
        public void goToAnchor(String anchor) {
          super.scrollToReference(anchor);
      }And this is the method I call from outside the JFrame containing the JEditorPane:
      public void goToAnchor(String anchor) {
         jEditorPane.goToAnchor(anchor);
      }Any help greatly appreciated ...

  • Anyone using ms sqlserver standard edition with XI 3.0

    wondering if anyone is successfully using ms sqlserver standard edition (not enterprise edition) with XI 3.0. I would like to set up a dev/test XI system and the standard sqlserver edition is less expensive than enterprise edition. I would like to confirm that it works ok first.
    thanks-

    Henry,
    I haven't tried but I think it will be successful with mssql server standard edition also. The following link gives the key difference between standard and enterprise edition.
    http://www.databasejournal.com/img/RS_servereditions_code.html
    Best of luck!
    regards,
    Felix

Maybe you are looking for