Swing embedded browser
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.