Question

What libraries/methods that you know of can do some basic HTML representation in Swing? Can you comment on your experience?

Was it helpful?

Solution

Many of the Swing controls (like JLabel) can render basic HTML content. JEditorPane can be used to display HTML pages. However, these controls are limited to HTML 3.2 support.

For a richer experience, I would use the JDesktop Integration Components.

JDIC provides Java applications with access to functionalities and facilities provided by the native desktop. It consists of a collection of Java packages and tools. JDIC supports a variety of features such as embedding the native browser, launching the desktop applications, creating tray icons on the desktop, registering file type associations, creating JNLP installer packages, etc.

OTHER TIPS

A good pure Java solution is JWebEngine. It render HTML 4 very good.

I haven't tried this in a while, but a quick google search shows some possibilities:

Are you trying to do this in an applet, or an application? If it's an application (or signed applet) you could potentially instantiate IE or Firefox within your application. Webrenderer acts as a Swing wrapper for this.

Swing has a built-in compontent called BasicHTML. I've never used it, but I think it should be sufficient for the basic stuff.

This has historically been a major weak point for Java, IMO. There are numerous ways to display limited markup, but very few that offer full featured HTML capabilities. The previously mentioned JDIC component is one option, however it is considered a "heavyweight" component and therefore does not always integrate well with Swing applications.

I am hopeful, however, that the new Webkit based JWebPane project will provide more advanced capabilities without all of the issues that we've had to deal with in the past. And, of course, there are several commercial options as well (IceBrowser is pretty good as an example).

I've just used SwingBox to display a quite simple HTML page, with good results.

The project includes a simple demo application which compares its BrowserPane component to JEditorPane, showing a far better result on complex pages (but still not comparable with a modern web browser).

The only issue I had is about unwanted scrollbars from the wrapping JScrollPane. The demo application seems to have the same problem. I can't tell where the issue originates. I'm using version 1.0.

Here a code fragment to show how simple is to use the component:

BrowserPane browserPane = new BrowserPane();
JScrollPane scrollPane = new JScrollPane(browserPane);
someContainer.add(scrollPane);

browserPane.setText("<html><b>Some HTML here</b></html>");
// or...
browserPane.setPage(new URL("http://en.wikipedia.org"));

Came across Lobo java web browser the other day.

Lobo is being actively developed with the aim to fully support HTML 4, Javascript and CSS2.

No experience with it though, but thought it may fit the bill for you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top