Browser components in Java

I’m currently putting together an application that will be implemented in SWT/JFace/RCP/Java, Swing/Spring Rich/Java, and Cocoa/Objective-C. I’m doing to see what they will look like on OS X, plus to learn a little more about the RCP, a lot more about Spring Rich, and a whole lot more about Cocoa/Objective-C.

One of the interesting aspects of this application is that it will have a Browser embedded in it.

I looked first at the SWT sources, since I’ve use the Browser component in Eclipse. In fact, you can drag an .html file from the Finder and drop into the Package Explorer or the Resource Navigator, then double-click on the .html file to open it in the Browser. This shows the decent integration Eclipse has on OS X, but there are still some holes, such as dragging out of an SWT app which isn’t supported yet. By the way, if you care about that, you can register with the Eclipse Bugzilla and then vote for it. Anyways, the Browser integration in Eclipse is quite nice, as it embeds the WebKit (which is what Safari uses) in your SWT/JFace/RCP app. It has hooks for actions such as openURL, back, forward, stop, refresh, as well as listeners for state changes. The org.eclipse.swt.browser.Browser class in org.eclipse.swt.carbon_3.0.1 plug-in is quite clean. It doesn’t go directly against JNI, which always seemed ugly. It hides most (or all) of the native calls in the org.eclipse.swt.browser.WebKit class, which depends on the swt-webkit library I talked about in an earlier post.

I then searched around for a good Swing Browser component. I found the relatively new JDIC project, which was kicked off around the JavaOne 2004 timeframe. The acronym stands for JDesktop Integration Components, with JDesktop Integration Components, which when translated into English means: “let apps be more native”. This has a browser component, but doesn’t have one yet on OS X. In fact, most of the OS X port of JDIC is incomplete. However, I would give this a try on Windows, Linux, and Solaris.

Searching further, I ran across an integration of WebKit with AWT by Dmitry Markman. The code is not as clean as the SWT Browser code, but it looks like the JDIC-Mac team will probably adopt it and clean it up. However, if you try the sample app included, it works pretty much like the SWT Browser widget, since it uses the same WebKit. I think the SWT Browser still has better support for actions and state listeners, though. I’m looking forward to the JDIC-Mac browser though, as well as any Dock/menulet support they could offer.

By the way, there is a good article about using the SWT Browser widget at the Eclipse Corner.

UPDATE: [11/2/2004 10:52AM EST] I’ll be looking at embedded browser components (in Java of course) on Windows tomorrow.

2 Replies to “Browser components in Java”

  1. Out of curiosity, what is this application going to do and why do you need to embed a browser? Are you going to show general web content or just your own? Would a 100% Java browser serve the same purposes?

    -j

  2. Joshua,

    The application is supposed to look like any other consumer application on Mac OS X, so that’s the reason it needs to use a native browser component. Anything else would look out of place (well except for embedding Gecko like Firefox, Camino, or Mozilla.)

    The basic idea is to be able to take notes on any site that you visit, as well as saving a snapshot of that site. This will allow people (tho I’m mainly writing it for myself) to make a scrapbook or journal that has important sites w/their thoughts. I visit a lot of sites and some of them are worth sharing or commenting on. However, I usually don’t have time right then, so right now I cut the URL and paste it into TextPad or Stickies or Omni Outliner. This is OK, but I’d like everything to be in one place, then be able to group certain sites together, perhaps by session or by topic I’m researching.

    Also, I wanted to see how the Look and Feel of each desktop app framework is like between SWT / JFace / RCP vs Swing / JDIC / Spring Rich vs Cocoa / Objective-C.

Comments are closed.