Skip to main content

Using JWebPane: common scenarios

Posted by ixmal on June 11, 2008 at 1:24 AM PDT

In the last blog posting I introduced a new component called JWebPane that renders HTML content in Java applications. Today I'd like to discuss the details of the practical use of this component. Let me start with typical use cases.


1. HTML Rendering

Since the necessity of employing this component in GUI applications appeared a long time ago, each solution, even simple rendering of web pages, is greatly appreciated. Moreover, in spite of the fact that the importance of interactivity is rising steeply, the correct rendering of up-to-date web content still remains a crucial requirement for an HTML component. It's worth mentioning that JWebPane copes with this task successfully along with the help of WebKit, one of the most advanced web engines.


2. Load event notifications

Let's move on to more interesting items. The load control of web pages and its resources is another highly demanded function required by many users. For this purpose JWebPane provides the following events: page loading start, external resource loading start, loading progress, loading stop or error, page loading finish, and resources loading finish. The exact set of events is not finalized yet, and new event types will appear soon.


3. Navigation

Sometimes using the HTML component is limited to one document, however, the HTML format itself implies tie-up and cross linking of documents. Navigation control, such as Back, Forward, Get URL and other commands, is naturally provided by JWebPane. The navigation function is closely related to transfers from one page to another. This is quite a controversial point: on the one hand, the application should maintain the history, but on the other hand, the component possesses information about which web sites were visited during the current session. That's why JWebPane provides the basic tools for history maintenance as well as the ability to retrieve history from the application.


4. Chrome

I always wondered where did the "chrome" term come from :-) This term is used to specify the HTML component environment, which is usually a browser window. Chrome typically includes support of the following elements: status bar, window title and icon, tooltips, window size, the component itself, and others. JWebPane, as an HTML component, doesn't have built-in support of these controls, however, it provides an API to implement those in the application.


5. What next?

Undoubtedly, the list of the JWebPane features is incomplete. I'm going to tell you more about the coolest ones, for example, how to create new windows or how to work with JavaScript. Additionally, we would like developers that are ready to use JWebPane share their ideas and visions. After all, they indeed define what kind of features should the convenient and handy HTML component have. Don't they?


Related Topics >>

Comments

Where is it?

Can we download a preview somewhere?

where is it :(

Sooner JWebPane will be released, better it would be. JWebPane will be an important component for Java, and a good news for SUN. If you like, read my detailled arguments here: http://www.jroller.com/dmdevito/entry/hotjava_may_come_back_due

Artem and All, Any updates to the status JWebPane would be appreciated. regards, -Frank

Please, please, please, I need this component urgently for my rich client app. When will it be released? This is ridiculous.

Any news?

Hello...is thera a news for JWebPane component?... When can I try this component?

Good news is that this delay allows JWebPane team to spend some time on plugins support. Watch for updates

Sorry for a significant delay with answer. JavaFX 1.0 release is of very high priority for Sun, and we do our best to release it is the best quality. Unfortunately, JWebPane component is not as stable now, so it will not be a part of 1.0 Uur current plans are to open JWebPane right after 1.0 is released, roughly in a couple of months.

where can I download it?

Seriously, when's the next update on JWebPane's progress? This really would be The Right Way to create an html widget, but announcing it, even informally, and then having it go underground for so long is building a heck of bad impression. What's up?

My impression is that JWebPane will be released as part of JavaFX. Is that right? I was disappointed to see that it was not part of the beta release of JavaFX.

I would like to see GUI construction via SVG, like KDE does. Looks great (try KDE4 games!), makes GUIs scalable and there's lots of established tools. Is that a planned use case?

Exciting! I'm looking forward to trying it out once its released.

I really like the idea of JWebPane. Here are some things I would like to be able to do.

  1. Programmatic data sources. So I can provide HTML content from a String or stream, or use an image I happen to have in memory as a bufferedImage. I'd like to Intercept AJAX requests and allow for content to be provided from code.
  2. Content filtering. So I can implement a system like AdBlock Plus and block unwanted content. Or rewrite it if there is a rendering bug like greasemonkey.
  3. Embed any Swing Component - currently this can be done with JTextPane
  4. Printing control - Some way of controlling pagination of web pages.
  5. Content Rendering Plugin - As an example say a user clicks on a PDF. I might want to change what happens to that content. Instead of having acrobat embed it's self. I could pass it on to Suns PDF reading libraries and display it in Java.
  6. Programmatic information about the HTML elements - This would allow me to create annotations or rollovers, highlight cells in tables, all on the Java side. I could "enhance" a web site that I actually don't control.
  7. Form level access - So I can pre-populate forms and click "submit". This would be really helpful in creating automated testing programs for web apps.
Thats all I have for now, I may think of more later. Thanks, Collin

  1. Cookie management - so I can see what information is being stored and by whom.
  2. Browser version Identification string - because web browsers have to play this game sometimes.
  3. Set Standard Fonts - A way to override a web sites specified font. Sometimes you need to do this if a font is not supported on your OS.
  4. Set standard Colors - A way set the standard colors. (link, visited link etc.)
  5. Replace Standard Controls - So a web page wants a TEXTAREA I can supply a JSpellCheckerTextArea or something like that. This way I can build in a spell checker like firefox has.
  6. Content caching - Access to the caching system (if there is one). Most web browsers do disk caching.

I missed the blog for several days, and it seems there are many interesting suggestions here :) Let me try to comment/answer some:
  • To liquid: I assume you mean insertion of Java/Swing components into a JWebPane, right? Why may you need this? As for plugins - yes, we plan to support at least Java and Flash, however I can't provide any details about this.
  • Currently, JWebPane component is based on stable branches of WebKit (safari-3.1 at the moment). This means JWebPane has roughly the same capabilities as a standalone Safari browser.
  • To aberrant: yes, the source of a page to display can be a String. As for images... Good idea, I'll think about images and other resources :)
  • There will be some API to control the content like URLs to load, cookies to accept, etc.
  • Printing will be definitely supported, however I can't provide much information about it now.
  • HTML forms access is done via javascript calls. Javascript can also be used to access/modify DOM elements and their styles, so there are no plans to introduce a separate DOM support as of now.
  • Cookies can be controlled via standard Java API for networking. Also, there are some chances that we'll implement a dedicated cookies store for JWebPane components.
  • Browser identification: yes, it is customizable.
  • Overriding standard fonts, colors, etc. is currently not supported, but some API for loading user/default CSS is in progress.
  • Standard controls are not supported. As I know, WebKit doesn't expose some HTML elements like as components, but handle them internally. However, it is an interesting issue to investigate.
  • Java <-> javascript transparent communication is somewhat we'd like to have, however at the current moment I don't know how difficult it is to implement.

I'm hoping that at some point HTML/CSS can take over some basic thick-client UI responsibilities. I'm imagining wizards, forms, and similar UI elements being coded in HTML/CSS, delivered and installed with the application, and rendered locally using JWebPane. The results from the forms would be locally processed without a web server. I think that would be pretty compelling...

Hi Artem, kudos to the talented engineers for developing a world-class HTML component. Looking at what you describe, JWebPane will be great addition to anyone building the next cool application. One question I will like to ask if JWebPane supports drag and drop to other Swing component. For example, if the text and image select from JWebPane can be drag to other component like JTextField, JButton so text can trigger event upon dropping or image can be saved upon dropping on another button. thx

  • Plugins (Flash, Acrobat) - This allows creating for example a crossplatform Flash player simply by serving a page that loads the plugin. Beware of a Java applet in a web page in the Java application.
  • Communication channel from web pages to Java application - This channel would have to be accessible through Javascript which would call a listener on the Java side.

Artem,

First of all - let me say that JWebPane is extremely important development. That is if it is not confined to be just the HTML viewer for Swing. See how many innovative applications exist on Mac OS X just because WebView api was made available to developers. If the trend continues at this rate - many new desktop (and we hope mobile) applications will use Web UI instead of anything else :-)
Our company (http://lablz.com) has built an open source Browser Bhoost around Android's WebView Java API. So we have first hand experience with WebKit wrapping in Java. Thus the questions:
  • have you reviewed WebView API on Android? For developers that want to create innovative Browser-based applications it is important to have one set of APIs.
  • will the ability to override the default cache manager be present? Specifically we need the ability to intercept all resource loading (not just be notified of them) and get/put cached copy based on our custom policies - for offline browsing support and more.
  • Safari is providing Liveconnect Java-JavaScript communications, so is this the way JWebPane is planing to approach the problem? It would be a pity to see something like a addJavascriptInterface() hack that Google has put in place of LIveConnect on Android.
  • is JWebPane planned for Mobiles or it is so heavy due to Swing that we can not hope for it?

Artem and All, I'm glad to hear that web mapping services render nicely inside JWebPane -- that's a key usage scenario for me as well. But, I would like to be able to add other Swing components inside a JWebPane. Why? Well, to add controls into the application. Maybe this would be too confusing to the user, we all have web browsing habits pretty well ingrained now. But it opens up some exciting browser <--> local machine interaction possibilities. And, if you want to customize the browser without hacking WebKit directly, this could be a great thing. My current application is called the GeoViz Toolkit (http://www.geovista.psu.edu/grants/cdcesda/software/), and it will be using JWebPane when it becomes available -- I'm looking forward to it! regards, -Frank

Hello Artem Words cannot describe how exited I am for the upcoming JWebPane component. I just have two questions and I realize you might not be able to answer the second one... :-) 1. Will the JWebPane support Flash. That is will I be able to play Flash videos inside it, like I can in other browsers? 2. Has there been published an estimate of a release date for this component? Thanks !

Hello again Artem Here's one addition to my questions above (of which the answer to nr. 1 is what I'm most interested in): As I understand it JWebPane will first be relased with JavaFX this fall. Will I be able to integrate that into my Swing code in some way? This might be a JavaFX question really, but it's so important to me to get a really good web browser functionality into my Swing project. Thanks again.

For me, the first important use case will be, at last, to embed Google Maps in my application without breaking Google's terms of use :-)

i'd really like to test the integration possibilities. Can we embed swing components, Scenario scenes, decora effects, jmc media, etc inside the JWebPane, and vice versa (where applicable), what about flash, silverlight, etc etc...

I thought it would be nice for instance to have plugins such as greasekit working, or to know you'd be able to code userscripts in java, (or at least have the technical ability to reimplement such a plugin) and so on.

And also, with features added everyday to webkit, what is the version used in the jwebpane (for things like the squirrelfish js interpreter, html5 and css features, and so on), and what is the plan for future webkit improvements to be usable (or not) in JWebPane ?

You could see the jwebpane as a way to use html as a layout engine, css as a visual engine, and java (javascript to some extent) as the behavior layer for swing components and applications. with the added value that there are huge number of tools that can help you.

I'm a developer of Automatic Vending Machines written in Java and our user interfaces are Web based.
For many years we've been using JRex an mozilla based Java Wrapper but the development is discontinued. It will be great to replace it, with an officially supported Web rendering component like JWebPane. Key features for as are: - LiveConnect: Access from java to javascript
- Java Plugin Access: To notify user actions to java through javascript
By the way is there any place where I can download JWebPane to use it (without downloading the JRE o something like this)? is there any way to make it work with JRE 1.4?

Will there an API to traverse (and modify) the DOM of loaded pages?

Yes, we do plan DOM access/modification API

The release model of JWebPane component is not finalized yet. It is expected as a part of JavaFX SDK and (I guess) will be also available as a standalone Java library, with its own versions not related to JDK. Again, this is no more than my thoughts and assumptions

Well, Google Maps works pretty fine and smoothly inside JWebPane, as well as many other maps sites :)

Hi Artem--thanks for updating us on the web pane--a question is, how will you all manage synchronizing with updates to WebKit? The major renderers (IE, Opera, Gecko, WebKit) all get updated pretty often, certainly much more quickly than new Java versions are released. I would like to see us avoid the chaos that came with bundling a buggy XML parser in JDK 1.4, which then was a part of the "core" platform. I understand this will be an important component to many people, and they will want it as part of the core, but on the other hand I think we'd like to take advantage of updates to WebKit as they are released. Thanks! Patrick