views:

320

answers:

6

I'm doing a Java application that requires to use a web browser inside the application.

I have seen some applications doing this, such as RSS readers when clicking in a feed in the left panel and opening the link in a right panel in the same application, and I would like to implement something similar.

Is it possible to do this in java? Is there any library included in the Java API? Do I need external libraries? Any information? IE, Firefox, Chrome, Opera? What should I use?

Thanks in advance

+1  A: 

There is the Flying Saucer XHTML renderer project which you may try.

It's kind of interesting. Take a look at this link: https://xhtmlrenderer.dev.java.net/

Kico Lobo
A: 

Try this question.

nasufara
+1  A: 

You could try the Eclipse SWT - this is the GUI toolkit that is used in the Eclipse project. In particular, the Browser widget should do what you need.

ajborley
A: 

As per one of the answers in darkassassin93's link, the native web browser as part of the DJ Project seems reasonable. I've tried it out briefly and it works pretty well. (Of course, you could wait until JWebPane finally gets released...whenever that might be)

Ash
A: 

You might look into the Desktop API.

trashgod
+3  A: 

The obvious one that everyone is avoiding is JEditorPane which is right in swing. It's a pig and very limited but for certain types of HTML rendering it does ok.

I have used it for simpler jobs.

As mentioned in the other links, Lobo Browser is another option. The cobra stuff in that is pretty good and handles a lot more pages than JEditorPane. I found it does all of my medium jobs but has some frustratingly unextensible parts of its design. I use it for my help systems and some non-AJAX heavy web work.

For anything like google maps, and those sorts of heavy AJAX style web applications, you are pretty much stuck with DJ Native as another poster and the other question responses mention. Since it's shelling out to a real browser underneath the covers it will handle any web site. The only down side is that you lose a certain level of control over what it's doing since you have to make calls to it through Java script and get events back through a similar mechanism.

As an example no sane person would need, I've had applications that rendered swing controls (reports, etc.) right into the web page on the fly. In JEditorPane this was confounding but possible. In Cobra it's almost easy but a few private or final methods requiring work-arounds. In DJ Native, it would be impossible without generating the image ahead of time and making it available via URL (either local or remote).

So it all depends on your needs. For free, there is no perfect solution.

PSpeed