Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 998311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:10:25+00:00 2026-05-16T07:10:25+00:00

I’m trying to render the contents of a the Java/Swing Cobra HTML renderer to

  • 0

I’m trying to render the contents of a the Java/Swing Cobra HTML renderer to an offscreen BufferedImage, for use elsewhere in my app:

 slideViewPanel.setDocument(document, rendererContext);
 BufferedImage test = new BufferedImage(300,300,BufferedImage.TYPE_INT_RGB);
 Graphics g = test.getGraphics();
 slideViewPanel.paint(g);

The resulting image in g shows a partially rendered page — sometimes the contents of the HTMLFrame before the new document was set; sometimes a half-rendered version of the new document. I gather this is because Cobra’s setDocument method just schedules the document for re-rendering, but I’m stepping through in the debugger and I don’t see a second thread to do re-rendering. Anyone have any insight into what might be happening here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T07:10:26+00:00Added an answer on May 16, 2026 at 7:10 am

    When the page has been parsed, you need to wait until all images are loaded before laying out the component.

    Intercept all image loading to make sure all images are completely loaded before laying out the component. I did this by overiding HtmlDocumentImpl.loadImage. (Had to subclass DocumentBuilderImpl and overriding createDocument to make it work.) I used a semaphore to wait until the result of a image.getWItdh is available.

    I had to set up a timer around the parsing, as some scripts may loop and never return. I have no idea if there is a better way of solving this.

    Regarding the layout, there is a a deal of cargo cult and experimentation that lead to the snipped below , so maybe you can try to remove some things.

                htmlPanel.setVisible(true); 
        htmlPanel.setPreferredWidth(DEFAULT_PAGE_WIDTH);
        logger.info("Calculating preferred size");
    
        // Get the preferred heigth for the current width.
        Dimension psvz = htmlPanel.getPreferredSize();
        Dimension min = htmlPanel.getMinimumSize();
    
        logger.info("prf :" + psvz);
        logger.info("min :" + min);
    
        // Enlarge to the minimum width (with a limit)
        int width = Math.min(MAX_PAGE_WIDTH, Math.max(DEFAULT_PAGE_WIDTH,
                psvz.width));
        int height = psvz.height;
    
        logger.info("width :" + width);
        logger.info("heigth :" + height);
    
        htmlPanel.setSize(width, height);
    
                // actually, htmlPanel is a subclass, and this method exposes validateTree. It may work without it.
        htmlPanel.forceValidateTree(); 
    
        htmlPanel.doLayout();
    
        setImageSize(width);
        logger.info("actual size:" + htmlPanel.getSize());
    

    I couldn’t figure out what a JFrame does with the HtmlPanel so that it paints its children properly.
    I had to paint using the children component; Ie either the htmlPanel.getBlockRenderable() or the frameset.

    Images are painted asychronous, (and the paints might abort), so before the BufferedImage can be used, all the image paints must be completed.

    I used a delegating graphics2d object overriding all the image paint methods to wait until the painting is completed.

    After that, i found that the html might benefit from a re-layout as all images sizes are known, so i invalidate the component and do the layout and painting again (or actually, I just call the code twice…)

    After that, the BufferedImage can be used. Maybe there is a simpler way.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to render a haml file in a javascript response like so:
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
i got an object with contents of html markup in it, for example: string
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I have thousands of HTML files to process using Groovy/Java and I need to
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.