Andrej Koelewijn

3/3/2005

Swing embedded browser

Filed under: — andrejk @ 11:34 pm

Over on javalobby Sebastian Ferreyra is wondering why the embedded browser hasn’t caught on. He thinks embedding a webbrowser in java Swing applications could be really usefull.

I Agree. On my current project we’ve implemented the reporting part of a swing application using an embedded browser.

My first thought for reporting was to use one of the existing reporting components, e.g., jasperreports. So i downloaded jasperreports and a visual report builder, ireport, to see how it worked. I didn’t like it: another xml language to learn, no separation of content and layout, and a visual designer which was a pain to work with. All in all, not a very productive way to create reports.

Actually, i’ve never liked visual reporting tools. I’ve used Oracle Reports in the past, and i found it rather frustrating: it feels like you’re forever moving your elements to get the layout just right.

Html is so much easier, nice separation of content and layout, with easy to use css style. I thought we’d be much more productive by just creating html reports and showing these using an embedded browser.

So first question is, which browser component? I tried the jdic browser component. It works, next question. How do we print? Jdic allows you to print documents by asking your desktop to print the document. Again, this works sufficiently, on windows that is. Your mileage may vary on other platforms, but this is not an issues for us.

How to generate the Html documents? Our solution is to use velocity. Embedding the velocity templating engine in your swing application is pretty easy. We simply put our javabeans based domain model in the velocity context, and can access all our data in our templates. Designing the html pages is pretty productive using the visual html editor in jdeveloper.

So what are the problems? Css support for printing. Well not really the css support, it’s more that the browser support for css for printing is lacking.

Our biggest problem is controlling the page margins and the page header and footer. Your browser controls the page margins and headers and footers. If you want to change this you have to change the page setup using the browsers options, you cannot do this in your css stylesheet.

Another problem is that current browsers do not support specifying page orientation through css. So if you want some reports printed in landscape and some reports using portrait, you have a problem.

Anyway, we can live with these problems and find that using html to create reports is a lot more productive than using an existing reporting component. And the situation will only improve when browsers will finally start supporting the newer css standards.

9 Responses to “Swing embedded browser”

  1. m Says:

    you could try:
    http://jrex.mozdev.org/

  2. Andrej Says:

    I looked at the jrex website, but it doesn’t make sense for our project. We’re distributing our application using java webstart, and using jrex the download grows another 6 megabytes. And quite unnecessarily as all computers already have a webbrowser installed.

  3. Shai Almog Says:

    The JDNC forums have a lengthy discussion about pure Java PDF rendering. Apparently Richard Blair (rbair from the JDNC team) has written such a component that actually works, and Sun has a preexisting component that is even better. The rbair version is already open source on the java.net jdnc-incubator project and the other version is going through Sun’s legal dept. I suggest you check it out, seems like the best solution for reporting.

  4. Andrej Says:

    Rendering is one thing, but how do you productively produce pdf reports? Is there a java tool that can convert html into pdf? I could create pdf report using jasperreports, but i find it a lot more productive to create my reports using html.

  5. Ankit Says:

    Hi Andrej,

    I tried using the jdic Desktop feature to print html documents. It works only if Internet Explorer is set as default web browser. I had Firefox as default browser and I got a blank plage when I tried using Desktop.print
    Have you also encountered this? Can you suggest a work-around? Thanks,

  6. Andrej Says:

    We’re also using internet explorer. Firefox isn’t supported. You have to use either internet explorer or Mozilla. I tried using mozilla, but ran into some bugs (the scrollbar wasn’t showing), so for now we’re sticking to internet explorer.

  7. pratik Says:

    Dear Andrej,

    i am facing the same problem. i am trying to generate reports using jasperreports. i succeed in generating reports in html, excel and pdf format on both client and server side.

    not the problem i am facing is that i am not able to view the reports using JasperViewer on the client side. if the client click on view report on the his maching, the report gets generated on the server machine and not on the client machine.

    kindly please help me out if you have any solution.

  8. Ilija Says:

    Hi Andrej,
    I have the same problem as Patrick. If you come up with any solution please help us!

  9. JAi Says:

    Hi Andrej,

    I am new to JasperReport.I am using JasperReport for creating Html,csv and pdf.I am having issues while generating Report.

    1.I have generated (say) ten pdfs reports My requirement is to Generate a single pdf incorporating all these ten files.
    2.xsl and html files created are distorted and missing contents which is pdf and csv created along with them.

    I think the main problem is ther is no proper documentation available for JasperReport.

    Please help

Leave a Reply

Powered by WordPress