Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: HTML in Swing Components in Cached Applet

  1. #1
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,972
    My Mood
    Hungover
    Thanks
    133
    Thanked 555 Times in 476 Posts

    Question HTML in Swing Components in Cached Applet

    Swing Components can contain html just fine, like so:

    JLabel lengthLabel = new JLabel("<html><u>" + i + " LETTERS</u></html>");

    The above causes the labels to be underlined in the below screenshot:


    I also use HTML to display the red "(-5 seconds)" in the "New Letters" JButton in the upper right corner.

    This works fine when the program is run as an application, and it works fine when it is used in an applet- the first time around. However, when running from a cached version of the applet (after navigating away form the page, or simply refreshing it), the HTML no longer shows up!



    Clearing the browser's and Java's cache fixes the problem temporarily, but the problem persists after the page is refreshed or navigated away from.

    I found a bug report with similar symptoms here: Bug ID: 7032814 Swing HTML components after navigating back to applet page

    There is an SSCCE in the bug report, but since it requires uploading the applet and viewing it in a browser, it might be easier to view my applet, look at the HTML JButton and JLabels, then refresh the page to see the problem:

    http://code.kevinworkman.com/TimeFor...rdsApplet.html (applet)

    Compare that to the executable Jar:

    http://code.kevinworkman.com/TimeFor...meForWords.jar (jar)

    Has anybody seen this bug before? Or, more to the point, does anybody know of a workaround for the bug?
    Last edited by KevinWorkman; May 30th, 2011 at 07:59 PM.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!


  2. #2
    Super Moderator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,099
    Thanks
    169
    Thanked 779 Times in 725 Posts
    Blog Entries
    5

    Default Re: HTML in Swing Components in Cached Applet

    Never seen this before, and its a strange behavior...have you tried to specify on the HTML page a no-cache policy? This would (hopefully) force clients to reload the applet on each visit (cool app BTW - fun to play...must take a look at the source). I wonder if java webstart demonstrates the same behavior

  3. #3
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,972
    My Mood
    Hungover
    Thanks
    133
    Thanked 555 Times in 476 Posts

    Default Re: HTML in Swing Components in Cached Applet

    Quote Originally Posted by copeg View Post
    Never seen this before, and its a strange behavior...have you tried to specify on the HTML page a no-cache policy? This would (hopefully) force clients to reload the applet on each visit (cool app BTW - fun to play...must take a look at the source). I wonder if java webstart demonstrates the same behavior
    Yeah, this is one of the weirder bugs I've seen. It seems to work fine from WebStart as well- and the applet, webstart, and runnable Jar are all running from the same Jar!

    I tried using an HTML/page no-cache policy, and I tried preventing the applet from caching (using the advice on this page: html - How to force a Java Applet to Load out of Cache - Stack Overflow ), but the problem persisted.

    My temporary fix is to simply remove the HTML, but this seems like a pretty major bug (ugh, all bugs seem major when they affect you).

    The buggy version is here: Time for Words

    And the newer, "fixed" version is here: Time for Words

    I'd still love to hear a workaround for this, but for now I'm just sick of looking at a screen!
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,972
    My Mood
    Hungover
    Thanks
    133
    Thanked 555 Times in 476 Posts

    Default Re: HTML in Swing Components in Cached Applet

    Quote Originally Posted by copeg View Post
    Never seen this before, and its a strange behavior...have you tried to specify on the HTML page a no-cache policy? This would (hopefully) force clients to reload the applet on each visit (cool app BTW - fun to play...must take a look at the source). I wonder if java webstart demonstrates the same behavior
    Yeah, this is one of the weirder bugs I've seen. It seems to work fine from WebStart as well- and the applet, webstart, and runnable Jar are all running from the same Jar!

    I tried using an HTML/page no-cache policy, and I tried preventing the applet from caching (using the advice on this page: html - How to force a Java Applet to Load out of Cache - Stack Overflow ), but the problem persisted.

    My temporary fix is to simply remove the HTML, but this seems like a pretty major bug (ugh, all bugs seem major when they affect you).

    The buggy version is here: Time for Words

    And the newer, "fixed" version is here: Time for Words

    I'd still love to hear a workaround for this, but for now I'm just sick of looking at a screen! I'm still very new to the HTML/CSS side of things- don't even get me started on getting my site to look okay in anything other than firefox!
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Super Moderator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,099
    Thanks
    169
    Thanked 779 Times in 725 Posts
    Blog Entries
    5

    Default Re: HTML in Swing Components in Cached Applet

    don't even get me started on getting my site to look okay in anything other than firefox
    Just wait until you try in Internet Explorer aka 'Internet Exploder'...in my experience, I design with firefox/Opera/Safari in mind - then must debug everything for Explorer. Hope you get the issue sorted out.

  6. #6
    Junior Member
    Join Date
    Jul 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: HTML in Swing Components in Cached Applet

    edit: upon further searching in the bugs.sun.com database, including the following in the init() method solves the problem:
    new javax.swing.text.html.parser.ParserDelegator();
    SwingUtilities.updateComponentTreeUI(this);

    the ParserDelegator doesn't have to be used by the program, just including this line seems to work, and all html text appears properly after reloads/refreshes/everything as expected

    http://bugs.sun.com/bugdatabase/view...bug_id=6992493
    Last edited by Renar; July 30th, 2011 at 06:11 PM.

  7. #7
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,972
    My Mood
    Hungover
    Thanks
    133
    Thanked 555 Times in 476 Posts

    Default Re: HTML in Swing Components in Cached Applet

    Quote Originally Posted by Renar View Post
    edit: upon further searching in the bugs.sun.com database, including the following in the init() method solves the problem:
    new javax.swing.text.html.parser.ParserDelegator();
    SwingUtilities.updateComponentTreeUI(this);

    the ParserDelegator doesn't have to be used by the program, just including this line seems to work, and all html text appears properly after reloads/refreshes/everything as expected

    Bug ID: 6992493 use of html fails to init when second applet inits from same JVM
    That's so weird, but thanks for the workaround!
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Java tip Sep 22, 2010 - "Screenshots" of swing components
    By helloworld922 in forum Java Swing Tutorials
    Replies: 3
    Last Post: June 6th, 2011, 01:25 AM
  2. How would you use HTML to embed a Java applet within it?
    By javapenguin in forum Java Theory & Questions
    Replies: 1
    Last Post: May 5th, 2011, 05:16 AM
  3. Swing Components Invisible as Startup
    By SpiceProgrammer in forum AWT / Java Swing
    Replies: 5
    Last Post: January 23rd, 2011, 01:26 PM
  4. Replies: 0
    Last Post: July 19th, 2010, 04:30 PM
  5. Painting swing components to an arbitrary position?
    By ScummyChimp in forum AWT / Java Swing
    Replies: 1
    Last Post: September 1st, 2009, 11:06 PM