Load HTML in a JTextPane

Hallo,
i try to load a simple html file into a JTextPane and then print out this file. I ve noticed, that my last (empty) td-tag-pair disapear. Why this happens? How can i avoid this?
thanks
bye
my html file:
<html>
  <head>
  </head>
  <body>
    <table border="1" height="200" style="border-style: solid" width="400">
      <tr>
        <td style="border-style: solid">
          1
        </td>
        <td style="border-style: solid">
          2
        </td>
       <td style="border-style: solid">
        </td>
      </tr>
    </table>
  </body>
</html>and my java programm:
import java.io.File;
import javax.swing.JFrame;
import javax.swing.JTextPane;
import javax.swing.text.html.HTMLDocument;
public class HTMLTest {
     public static void main(String[] args) {
          try {
               JFrame frame = new JFrame();
               frame.setSize(400,300);
               frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
               JTextPane pane = new JTextPane();
               HTMLDocument doc = (HTMLDocument) pane.getEditorKitForContentType("text/html").createDefaultDocument();
               doc.setAsynchronousLoadPriority(-1);
               pane.setDocument(doc);
               File f = new File("1.html");
               pane.setPage(f.toURL());
               frame.add(pane);
               frame.setVisible(true);
               System.out.println(pane.getText());//Here it happens! Where is my last (empty) td-tag-pair?
          } catch (Exception e) {
               e.printStackTrace();
}

Hey,
It works fine for me.....Ur empty tag is showing up!......and one more suggestion is don't add data directly to JFrame..u have to call...getContentPane()..and add it...may be u have posted that thing wrongly ..anyway i have modified and it's working fine for me!

Similar Messages

  • Font color issue with inserted HTML content in JTextPane (HTMLEditor)

    Hi everyone,
    I have a very serious issue with the HTMLEditor I'm developping. This editor is a little bit special since it is intended to edit blocks of HTML content that are loaded when the editor is initialized.
    You can in fact decide to keep this loaded HTML content or start a new HTML document from scratch. Alright, now my issue is the following :
    When text is loaded, it's properly rendered. I have a functionality which let's you see the HTML code from the HTML document used in the editor, so I can check and see if code is correct, and yes, it's correct.
    The problem is that when I try to change the color attribute of some text on my loaded content, nothing happens ! I don't know what's the matter with this bug, I only have it with the color attribute, with every other attribute everything's fine (font, size, etc.)
    The funny thing is that, after I change another attribute for loaded content, like font family, then changing color attribute funcionnality starts to work again !
    I've also noticed that I don't have any of these problems when I start my HTMLDocument from scratch (when I create a new HTML document and start typing text).
    Another weird thing, is that I have a feed-back feature in my editor which reflects attributes for text over which the caret is positionned. For example, if you put caret over red text, the color combo box displays a red value, you know, just like in MS Word. Well, with my loaded content if I have a red text color and I decide to put it in green, the color combo box displays the green value when I click over text for which I have changed color, but in my JTextPane it's still red !! And when I try to see the HTML code generated nothing has changed, everything is still red !
    There is something really strange here, this means that when I get the attributes of the loaded text from the HTMLDocument, color appears to be green, but when it gets rendered in the JTextPane it's still red and when it gets anlyzed to produce the corresponding HTML code, these changed attributes are not taken into account.
    But the most weird thing above all, is that I don't have this bug everytime, sometimes I start my HTML editor applet and it works fine, and some other times this color issue is bakc there. Is this a known bug for Swing API or not ?
    =============
    This is more or less my technique :
    //I declare a global reference to my HTMLDocument
    HTMLDocument _docHTMLDoc;
    //Create a JTextPane
    JTextPane _tpaEditor = new JTextPane( );
    //Set type content to automatically select HTMLEditorKit
    _tpaEditor.setContentType("text/html");
    //Get a referene to its HTMLEditorKit
    HTMLEditorKit _kitHTMLEditor = (HTMLEditorKit) _tpaEditor.getEditorKit( );
    //I then have a function to create new documents
    void newDocument(){
      _docHTMLDoc = (HTMLDocument) _kitHTMLEditor.createDefaultDocument();
      _tpaEditor.setDocument(_docHTMLDoc);
       //I do other stuff wich are not important to be shown here
    //I then have another function to load content
    void loadContent(){
       //I get content from a HashMap I initialized when I started my applet
       String strContent = (String)_mapInitParameters.get("html_content");
       //I set content for my editor
       _tpaEditor.setText(strContent);
    //Notice.. I have tried many other ways to load this text : via HTMLEditorKit and its insertHTML method, I
    //have also tried to store this content in some reader and make HTMLEditorKit read it... and nothing,
    // I always get the bug
    //To change color it goes like this :
    JComboBox _cboColor = new JComboBox();
    //I correctly initialize this combo with colors
    //then I do something like this
    ActionListener _lst = new ActionListener(){
       public void actionPeformed(ActionEvent e){
          Color colSel = (Color) _cboColor.getSelectedItem();
          MutableAttributeSet mas = new SimpleAttributeSet();
          StyleConstants.setForeground(mas,colSel);
          setAttributeSet(mas);
    _cboColor.addActionListener(_lst);
    //Set Attributes goes something like this
    private void setAttributeSet(javax.swing.text.AttributeSet atrAttributeSet) {       
            //Get current 'End' and 'Start' positions
            int intCurrPosStart = _tpaEditor.getSelectionStart();
            int intCurrPosEnd = _tpaEditor.getSelectionEnd();
            if(intCurrPosStart != intCurrPosEnd){
                //Apply attributes to selection
                _docHTMLDoc.setCharacterAttributes(intCurrPosStart,intCurrPosEnd - intCurrPosStart,atrAttributeSet,false);
            else{
                //No selection : apply attributes to further typed text
                MutableAttributeSet atrInputAttributes = _kitHTMLEditor.getInputAttributes();
                atrInputAttributes.addAttributes(atrAttributeSet);

    hi, friend!
    try this:
    void setAttributeToText(JTextPane pane, int start, int end, Color color) {
    MutableAttributeSet new_att = new SimpleAttributeSet();
    StyleConstants.setForeground(new_att,color);
    HTMLDocument doc=(HTMLDocument)pane.getDocument();
    doc.setCharacterAttributes(start,end,new_att,false);
    It works fine in my Application, hope will work in yours, too.
    good luck.

  • HTML in a JTextPane

    I am displaying simple html in a JTextPane. I've built simple pages with <Input> tags, I load them in the JTextPane and it works - looks great. I can input into these fields, but my question is how can I programmatically get the entry values I've made?

    Hi Puce thanks for the comment.
    Actually I am never submitting this web pages - I created a component to display web pages and gather the resulting input into a Properties file. The purpose of this is to be able to create sophisticated setup/configuration screens (images, layout, etc) in J2SE using html, so like I said I'm never submitting the pages.
    Anyway, I worked out how to do what I needed - I subclassed the HTMLEditorKit and kind of hacked what it's doing. It's pointless, but pretty sweet.

  • How to Load a SWF in Dynamically Loaded HTML

    Hello,
    I have a Flash movie with a multi-line text field that loads
    HTML text. As per the below Macromedia documentation I have swfs as
    images inside my HTML text.
    I'm trying to find a way to pre-load these swfs - if I do
    loadmovie to load the swf, when the html file is loaded will it
    need to reload the swf from scratch or will it take my loaded
    version? I'd love to show a "loading" message in the text as the
    swf was loading but am unsure how to do this now that I have the
    swf reference embedded in the html text.
    Any ideas?
    Thanks!
    Julia
    From the Macromedia documentation:
    Image tag (<img>
    The <img> tag lets you embed external JPEG files, SWF
    files, and movie clips inside text fields. The <img> tag has
    one required attribute, src, which specifies the path to a JPEG
    file, a SWF file, or the linkage identifier of a movie clip symbol.

    Thanks - your answer is exactly what I was looking for.
    I'm noticing that every swf I load via dynamic HTML is
    distorted - is there a way to prevent this? I can set the width and
    height of each swf in the HTML, which works ok, but then I run into
    a problem when I try and have a component item (like an accordion)
    included in the dynamic text field. It works properly, and the
    framing is sized correctly, but the guts are still skewed. I
    haven't been able to figure out why the swfs are being distorted in
    the first place.
    Any ideas?
    Thanks,
    Julia

  • "JavaScript Error encountered while loading HTML"

    Hi,
    I have been trying to embed a google map on a InDesign CC page, NO LUCK YET.
    I spoke several Adobe InDesign help line people, unfortunately they couldn't solve it.
    Here is the problem: I tried with different versions
    1- version) I copy of a map code and paste the code on a page, shows grey square round image and nothing (no map)
    2- version) From Object menu:
        "Select insert HTML.."
        "This is an HTML snippet."
    I paste the codes into HTML box, a second later, small box message,
         "JavaScript Error encountered while loading HTML"
    I have 64bit 12gb ram computer with windows 8.1
    InDesign CC version 9.2.1 x64
    Java 7 update 51
    I have tried with Internet explorer, google chrome and fire fox, and different maps, still no luck.
    Can anyone solve this problem?
    Thank you in advance,
    atamtan

    Yes, Google changed something and not for the better.
    Try a bing map instead. They work fine.

  • Why does DW CC 2014.1 Fluid Grid load HTML file that contains Google Analytics Tracking Code script so slowly?

    I exclusively work in Fluid Grid since my site is a Responsive Web Design.  I'm having trouble with slow load time in DW CC 2014.1, when my file, as they all do of course, has the Google Analytics Tracking Code script.
    I'm on a Windows 8.1 using a Dell Precision M3800 Laptop with Memory 16GB (2x8GB) 1600MHz DDR3 . Each of our site's 180 or so web pages, of course, has its Google Analytics Tracking Code script. It is placed, following Google instructions, as the last entry in the <head>.  Google Analytics does not instruct to place the script in the JS Folder with an scr to it, but rather in the <head>.  It takes up to one and a half or two minutes for DW CC 2014.1 to load the Google Analytics Tracking Code script .  That is, the grid does not show in Live View until finally analytics.js shows up in the Document Toolbar. A minute or two can add up when every page you load takes this long.  And, making new Fluid Grid pages, as is done, through the Save As command; every new page made you have to deal with the minute or two wait time since all those pages have the Google Analytics Tracking Code script.  Therefore, this time component alone, assuming I'm accessing and/or making 20 pages per week (and in our business this is easily the case) the math is that I'm wasting between 17 and 35 hours per year just with DW CC 2014.1 loading the much needed Google Analytics Tracking Code script.
    I have loaded HTML files that do not have the Google Analytics Tracking Code script as a test and those files load at the normal quick speed.
    Therefore, the new Chromium Embedded Framework browser engine has a serious load problem when it confronts an HTML5 file with a Google Analytics Tracking Code script.  Oddly, the prior DW CC 2014 version, with the old browser engine did not have this slow-load problem since I was loading these same files in that DW CC version up until October 8th or so.
    I think this new browser engine is a Google platform that apparently has a problem rendering or loading a Google Analytics Tracking Code script.  That makes no sense.
    Anyone else had this particular slow-load problem with DW CC 2014.1?
    Thanks.

    Wow.  That sure solved the slow-load problem, at least using your suggested snippet in a simple test HTML file.
    Per Google's instructions, I pasted the snippet before the closing </head> tag.  And, even in that positioning in the file; the file loaded at the speed (about one second) that it did prior to DW 2014.1.
    Two questions.
    Will this snippet provide the same tracking data as my current GA snippet?
    Because my current GA snippet is in about 200 web pages, can I retain the old snippet in most of them and place the new snippet in my approximately 5 main web pages as well as my templates so my new pages, as well as my main pages, have the new snippet.  That is, can I have both snippets (i.e. old snippet in earlier pages and new snippet in main pages and new pages to be made going forward) in my website at the same time?
    Of course I would not have both the old and new snippet in a web page at the same time.
    I greatly appreciate any assistance anyone can provide me on this issue and thank all of you in advance.
    I've provided code for both simple test files below.
    Code for Asynchronous Syntax of GA script:
    <!doctype html>
    <!--[if lt IE 7]> <html class="ie6 oldie"> <![endif]-->
    <!--[if IE 7]>    <html class="ie7 oldie"> <![endif]-->
    <!--[if IE 8]>    <html class="ie8 oldie"> <![endif]-->
    <!--[if gt IE 8]><!-->
    <html class="">
    <!--<![endif]-->
    <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Test Asynchronous GA Tracking Code In Head</title>
    <link href="css/boilerplate.css" rel="stylesheet" type="text/css">
    <link href="/css/style.css" rel="stylesheet" type="text/css">
    <!--
    To learn more about the conditional comments around the html tags at the top of the file:
    paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/
    Do the following if you're using your customized build of modernizr (http://www.modernizr.com/):
    * insert the link to your js here
    * remove the link below to the html5shiv
    * add the "no-js" class to the html tags at the top
    * you can also remove the link to respond.min.js if you included the MQ Polyfill in your modernizr build
    -->
    <!--[if lt IE 9]>
    <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
    <script src="js/respond.min.js"></script>
    <script type="text/javascript">
      var _gaq = _gaq || [];
      _gaq.push(['_setAccount', 'UA-73425000-1']);
      _gaq.push(['_trackPageview']);
      (function() {
        var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
    </script>
    </head>
    <body>
    <div class="gridContainer clearfix">
      <div id="div1" class="fluid">
        <div id="test1" class="fluid ">This is the content for Layout Div Tag "test1"</div>
       <div id="test2" class="fluid ">This is the content for Layout Div Tag "test2"</div> 
    </div>
    </body>
    </html>
    Code for older GA script snippet:
    <!doctype html>
    <!--[if lt IE 7]> <html class="ie6 oldie"> <![endif]-->
    <!--[if IE 7]>    <html class="ie7 oldie"> <![endif]-->
    <!--[if IE 8]>    <html class="ie8 oldie"> <![endif]-->
    <!--[if gt IE 8]><!-->
    <html class="">
    <!--<![endif]-->
    <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Test GA Tracking Code In Head</title>
    <link href="css/boilerplate.css" rel="stylesheet" type="text/css">
    <link href="/css/style.css" rel="stylesheet" type="text/css">
    <!--
    To learn more about the conditional comments around the html tags at the top of the file:
    paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/
    Do the following if you're using your customized build of modernizr (http://www.modernizr.com/):
    * insert the link to your js here
    * remove the link below to the html5shiv
    * add the "no-js" class to the html tags at the top
    * you can also remove the link to respond.min.js if you included the MQ Polyfill in your modernizr build
    -->
    <!--[if lt IE 9]>
    <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
    <script src="js/respond.min.js"></script>
    <script>
      (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
      (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
      m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
      })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
      ga('create', 'UA-73425000-1', 'auto');
      ga('send', 'pageview');
    </script>
    </head>
    <body>
    <div class="gridContainer clearfix">
      <div id="div1" class="fluid">
        <div id="test1" class="fluid ">This is the content for Layout Div Tag "test1"</div>
       <div id="test2" class="fluid ">This is the content for Layout Div Tag "test2"</div> 
    </div>
    </body>
    </html>

  • Some email images do not show while using the icloud web app.  I can see the images on my IOS devices and in gmail but I only see a small gray box in the icloud web mail app.  Load HTML images is checked in preferences.

    Some email images do not show while using the icloud web app.  I can see the images on my IOS devices and in gmail but I only see a small gray box in the icloud web mail app.  Load HTML images is checked in preferences.  Is there a solution to this issue?

    I've seen the opposite issue.  My wife recieved an email with jpg attachments.  She couldn't see or print them on her iPhone 4S but they showed up fine in iCloud or in the mail app.  I had her forward the email to herself and then they showed up.  I assume there is an issue with how Apple is processing the attachments and resending causes them to get reformatted in a way that makes them easier to handle.
    So yeah.  Seems like some bugs.  Hope Apple fixes them soon.

  • How to create a popup window to load HTML page in AIR application without using any mx or spark?

    How to create a popup window to load HTML page in AIR application without using any mx or spark components?
    I need to load the HTML page in popup in AIR application without using any of the <mx> or <spark> components. I need to open in the application itself not in the browser.(If we use navigateToURL() it will open in th browser)

    Can we achieve this? can somebody help me on this scenario..

  • How to load html page or website in flash as3

    hi
    how to load html page or web link (www.google.com)  in flash as3.
    please help me...

    Use the navigateToURL function...
    var url:String = "http://www.wherever.com";:
    var req:URLRequest = new URLRequest(url);
    navigateToURL(req);
    OR in one line...
    navugateToURL(new URLRequest("http://www.wherever.com"));

  • How to load Html page in Flex 4 application

    Hi All,
              I am able to load html page in flex 3 application but i am unable to load in flex 4 application.
    How can i do it.
    Can any help me regarding this.
    Thanks in Advance
    Raghu.

    This may help - http://www.deitte.com/archives/2006/08/finally_updated.htm
    Thanks and Best regards,
    Pallavi Joshi | [email protected] | www.infocepts.com

  • How to load html web in flash?

    How to load html web inside flash as2/as3?

    Hi spoboyle, thanks for your reply!
    Will the above methods works for a web app if I want to load something like these in flash?
    <iframe src=http://www.flickr.com/slideShow/index.gne?group_id=71332142%40N00 frameBorder=0 width=500 height=500 scrolling=no></iframe>
    or maybe this
    <object width="400" height="300"> <param name="flashvars" value="offsite=true&lang=en-us&page_show_url=%2Fphotos%2Fabefilm%2Fsets%2F74457524564396771%2Fshow%2F&page_show_back_url=%2Fphotos%2Fabefilm%2Fsets%2F7215 7622564396771%2F&set_id=72121762456636771&jump_to="></param> <param name="movie" value="http://www.flickr.com/apps/slideshow/show.swf?v=109615"></param> <param name="allowFullScreen" value="true"></param><embed type="application/x-shockwave-flash" src="http://www.flickr.com/apps/slideshow/show.swf?v=109615" allowFullScreen="true" flashvars="offsite=true&lang=en-us&page_show_url=%2Fphotos%2Fabefilm%2Fsets%2F72153224564396771%2Fshow%2F&page_show_back_url=%2Fphotos%2Fabefilm%2Fsets%2F72237624564396771%2F&set_id=72427624564396771&jump_to=" width="400" height="300"></embed></object>
    UPDATED: I downloaded the wrapper and read the README and docs. Im still unable to use it, how do I use it inside my flash to load html?

  • Loading HTML/WORD Documents in Oracle8i

    How do we Load HTML/Word or other content Documents in Oracle8i Database.
    And is there a GUI interface available to insert documents.
    Genereal users cannot probably use SQL Loader for that
    Replies urgetntly required so please kindly mail to [email protected]
    thank you
    -nandeep

    This is documented in http://technet.oracle.com/doc/oracle8i_816/inter.816/a77063/cdefaul5.htm#1000908
    examples in http://technet.oracle.com/doc/oracle8i_816/inter.816/a77063/aload.htm#272
    easiest is INSERT, frequently done when http-posting text from an html form into a varchar2
    iFS also provides several text insert methods.

  • Is it possible to load HTML data into BW?

    Is it possible to load HTML data into BW,I have read in some places that is is possible but I cannot find much documentation on this on Google or other SAP sources.
    If anyone has some documentation or general how-to guides that would be great!
    Even a general overview in your own words would be a great starter.
    Thank You
    Points will be assigned

    Please check these links n see if it helps
    http://help.sap.com/saphelp_nw2004s/helpdata/en/78/ef1441a509064abee6ffd6f38278fd/frameset.htm
    http://sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/icc/bw-udc-jdbc%20universal%20data%20connect%20jdbc%20interface.pdf
    http://help.sap.com/saphelp_nw04/helpdata/en/00/f01640dc88e769e10000000a155106/content.htm
    Regards,
    R.Ravi

  • Is It possible to load Html page inside Adobe Flash...?

    Hi Everyone!
    Is It possible to load Html page Inside Adobe Flash CS5.
    Any help would be a great help...!
    Originally, i wanted to bring in through <IFRAME> but i don't see that flash understands that.
    Thanks in advance!
    -yajiv

    Not exactly sure how you where planning to display that HTML content in relation to the overall page, but given the limitations of Flash... that may just not be possible...
    But, it would be a simple matter to display an HTML iframe over the top of or behind a Flash .swf... So while the iframe would not be a part of the .swf, it certainly could be designed to make it look as though it were.
    Controling the stacking order or layering of content on a Web page is accomplished through z-indexing. Correctly positioned and z-indexed, the iframe could apear over the top of the .swf... the .swf in effect being the background... OR the iframe could appear behind the .swf and with a transparent section in the .swf, the iframe would appear through that hole. If there is navigation or links in the iframe, they will be blocked by the .swf though.
    http://www.w3schools.com/cssref/pr_pos_z-index.asp
    But this may be an option....
    Best wishes,
    Adninjastrator

  • Is It possible to load Html page inside Adobe Flash Professional..?

    Hi Everyone,
         Is It possible to load Html page inside Adobe Flash Professional or Adobe Flex. Thanks in Advance.
    -Vijay

    probably not the way you are thinking.
    flash textfields and their extensions have a limited number of html tags they can parse so, in general, html from most web pages will not display, as expected in flash.

Maybe you are looking for

  • Administering broadvision on Oracle 8.0.5 on Solaris 2.6

    Hi All, My company is planning to set up broadvision on Oracle 8.0.5 running on Solaris 2.6. As the DBA, I need to provide some strategies for the following areas: Performance monitoring tools for monitoring and tuning the database remotely. Use of C

  • Some questions about sharing resources, eg via dropbox...

    Experts- I see that one way to share all topics with another RH user is to open the Topics List pod, select all topics, then drag the lot to Resource Manager (eg, the Dropbox folder therein). Is there a way to add images and other non-topic files in

  • Keyboard not working after cleaning

    I cleaned the flat aluminum keyboard with a spray that sprays foam and now some keys on the keyboard are not functioning. I have used this spray on other keyboards without any problem. Yesterday the keys 1, 2, Q, W, A, S, Z, X and the key to lower th

  • Firefox 4 won't shut down

    Since updating to firefox 4.0.1 (for XP), the only way I'm able to shut down the program is through the Task Manager. The X in the top right corner is ignored, as is the Close command in the taskbar.

  • Bluray locking up in Encore CS4 on Windows 7 RC1

    Greetings, I am running Adobe CS4 Master Suite on Windows 7 RC1 64 bit OS setup and have a unique issue. When I import my footage rendered from PPro into Encore CS4 everything works fine. Also when I build the project into a DVD I have no issues what