Christopher has posted 9 posts at DZone. You can read more from them at their website. View Full User Profile

Mixing Swing and Native Components

  • submit to reddit

DJ Native Swing is a nice solution to embed native components (Web Browser, Flash Player, etc.).

There was still a general issue that this library did not resolve though: the possibility to mix heavyweight and lightweight components with lightweight components on top, to change their Z-order or re-parent them.

Fortunately, The release 0.9.3 offers interesting advances in this area.


Component mix


Using these features is as simple as changing some options before instanciating native components, in order to extend their behavior.

You can try all the features (including the new options) with the Webstart Demo:

The Webstart demo is configured to work on Windows. It also works on Linux (GTK, x86/i386) where XULRunner is installed. Note that this demo is part of the release package.

In my opinion, this gets us one step closer to proper native integration. What do you think? Have you got any comments or suggestions?



Native Swing:
The DJ Project:

Published at DZone with permission of its author, Christopher Deckers.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)


Rob Blanchard replied on Fri, 2008/02/08 - 11:21am

Is there any configuration help for getting this to run under Linux?  I think this is a great project, assuming I could actually get it to work.

I've downloaded  xulrunner, untarred, and then run the xulrunner --register-global command.

Then I set MOZILLA_FIVE_HOME to the xulrunner folder, and added MOZILLA_FIVE_HOME to LD_LIBRARY_PATH.

When I attempt to run the DJNativeSwingDemo, the demo comes up, but when going to the JWebBrowser | Simple Example, I don't see anything rendered in the web browser space.  If I try entering other addresses, I can see on the status line that it is transferring data, but nothing is actually displayed in the main browser area.

 What am I missing?


Rob Blanchard replied on Fri, 2008/02/08 - 11:50am in response to: Rob Blanchard

Nevermind, I think I answered my own question.  I was using Java 5.  Java 6 appears to work fine.

Christopher Deckers replied on Sun, 2008/02/10 - 5:18am in response to: Rob Blanchard

Hi Rob,

The problem is a bug in the Java 5 VM on Linux that prevents the components from being displayed. This bug was fixed in Java 6, I just wish the fix eventually gets backported to Java 5.

On Windows, Java 5 and 6 work fine. 


SWTSwing - DJ Project - UDoc - DZone Voting

Venkat Kommaraju replied on Wed, 2008/02/27 - 11:50pm

Hello Chris,

DJ project is certainly a fantastic stuff that should ideally have a great future. We'd like to contribute to it as well.

I wonder if JWebBrowser on Linux is fool proof. I had XURLRunner and the SWT.jar file all set appropriately.

The browser is able to open normal web pages  with images and so on. But websites built with Flash/Flex do not show up. That was problem #1.

JFlashPlayer (I trust uses the same native browser internally) also does not show up.

Here is my problem summary:

Objective: Play SWF files on a JFrame (more like browser opening the SWF file as file://XXXX.swf).

Problem: Works well on Windows with no issues. On Linux, the same code pops up message to save the file to disk or save as dialog. On Linux again, even if I have this swf embedded in a HTML and open that HTML, the flex/flash portion of it does not show up.

I am using JDK 1.6+, XURLRunner 1.8.1, Eclipse SWT latest from and DJNativeSwing-0-9-3.

Can you suggest what should I be doing to achieve my objective?



Christopher Deckers replied on Thu, 2008/02/28 - 2:16am in response to: Venkat Kommaraju

Hi Venkat,

You are right: on Linux, it was not stable enough. I was relying on the SWT_AWT bridge (fromSWT), but it really is unstable when we start pushing it to the limits.

Fortunately, I decided to make an architectural change (ditching this SWT_AWT bridge, but still using SWT), and the next version (0.9.4) really is more stable. I hope to release it in the coming days.

If you want to try a preview of this coming release, don't hesitate to contact me by e-mail.




Venkat Kommaraju replied on Thu, 2008/02/28 - 4:31am

Hello Chris,

I appreciate your quick response and am glad that we stand on the same understanding.

I shall be certainly interested to try it out and also contribute to it as much as I can.

Can you please send me the dump to venkat at prodigygroupindia dot com ?

Meanwhile, I am still trying to see what best can I do to get this thing working on Linux.


Lin replied on Thu, 2008/03/27 - 4:13pm

This sounds like a great product.

It works perfectly on Windows. But I have problem running the browser on Linux with 0.9.4 release.

I created a simple browser example which launced from Java Web Start. I set following system properties in the browser to force it use "mozilla":

 System.setProperty( "dj.nativeswing.ui.webbrowser", "mozilla" );

boolean isWindows = (System.getProperty("").indexOf("Windows") >= 0) ? true : false;

if ( !isWindows ) {

System.setProperty "org.eclipse.swt.browser.XULRunnerPath",  "/opt/xulrunner/");


else {

    System.setProperty( "org.eclipse.swt.browser.XULRunnerPath", "C:\\builds\\webclient\\xulrunner");


This works fine on Windows, but on Linux there is nothing displayed on the browser area.

I'm using Java 1.6.01.

To verify the xulrunner is installed properly, I also tried a simple SWT browser on linux, it works fine. I also set

 System.setProperty( "dj.nativeswing.messaging.debug", "true" );

and I saw messages send/receive to other JVM running NativeInterfaceHandler.


Any sugestion on this problem? I can provide the source code of my example if you want it.



Christopher Deckers replied on Thu, 2008/03/27 - 4:20pm in response to: Lin

Hi Lin,

Yes, I do have a suggestion: to update to a later version of Java. This bug was fixed in a later version (Java 1.6.03 if I remember correctly).

Hope this helps!


Lin replied on Fri, 2008/03/28 - 8:58am

Hi Chris,

Thanks for your quick reply and the great product.

 It now works on Linux with java1.6.05.  I'm going to try it on Solaris too.

What I am trying to do is an embedded browser in our JWS product. I tried several other free embedded browsers, corba, webclient,  and jdic etc. This one fits most of our requirements.





Christopher Deckers replied on Fri, 2008/03/28 - 9:25am in response to: Lin

Hi Lin,

I have to admit that I never try on Solaris, but it may work! Please let me know the result of that investigation.

Don't hesitate to contact me by e-mail directly rather than on this thread.




suresh kumar replied on Tue, 2008/06/10 - 2:53am


I tried in Linux with JAVA 6,still the Web Browser shows the data Transfering.What is the problem.Any full Package available foe Linux.


Christopher Deckers replied on Tue, 2008/06/10 - 2:58am in response to: suresh kumar


I don't understand the issue you are having. Maybe you could send me an e-mail to explain what you are trying to do that does not work.



suresh kumar replied on Tue, 2008/06/10 - 4:15am in response to: Christopher Deckers

Dear Chris,

   1.I Install the Java 1.6 and XULRunner engine,SWT in LINUX.

  2.Run the DJNativeSwingDemo.

  3.When I attempt to run the JWebBrowser -Simple Example,I can see the Transfering data in the status bar,but nothing displayed in the main browser area.

 What is the problem.

veera sivakumar replied on Tue, 2008/06/10 - 4:42am in response to: Christopher Deckers

Dear Christopher,

                        We have  developed java application in Slackware linux 12.0 and we have required to make the communication(integration ) with flash(swf) file. For this purpose we have downloaded the DJNativeSwingDemo, java 1.6 and XULRunner- and installed successfully.

                        As per the steps, I have to set MOZILLA_FIVE_HOME and LD_LIBRARY_PATH correctly. And then I run the DJNativeSwingDemo.jar and select "Simple Example" Under JWebBrowser in the main window. It is showing "Transferring the data from" in the task bar for long time but  the web page  is not opened.

Pls suggest me for this problem.



Christopher Deckers replied on Tue, 2008/06/10 - 4:48am in response to: veera sivakumar


Maybe you are using an early Java 1.6. The first releases of Java 1.6 on Linux were not showing native components.

Please try to upgrade your version of Java to the latest Java 1.6.



Venkat Kommaraju replied on Tue, 2008/06/10 - 5:27am

Folks this is Venkat.

We have used the DJ component for one of our services to a client and it works fantastic with

Java 1.6, XULRunner

If it is just a browser, for instance, theoritically there should be no issues running DJ demo.

Alternatively, if the page has some flash/flex content, you might want to take care of looking for mozilla flashplayer plugin (I believe it is or to reside under XUL Runner as well.

 Otherwise, it works very well. By the way we have Java 1.6 update 10 early access, so thats the most recent and it works with it too. Just to support Chris's point.



veera sivakumar replied on Tue, 2008/06/10 - 5:54am in response to: Christopher Deckers

Dear Chris and Venkat,

                         I have re-install the latest jdk1.6 in linux and run the DJNativeSwingDemo.jar. It is working fine.

Thanks a lot for your suggestion.

Thanks & Regards,

Veerasivakumar .V 


Dimoklis Despotakis replied on Thu, 2008/11/06 - 5:00am

Dear Mr. Deckers,

 i have embedded the JWebBrowser  in my application and everything works fine.It is an excellent work!

I have a problem when i use the component inside a JPanel and actually inside a docking framework with close-DnD-repaint fetaures. In the Exception handler you log is as follows:


"java.lang.IllegalStateException: A native component cannot be re-created after having been disposed! To achieve re-parenting or allow re-creation, set the option to defer destruction until finalization (note that re-parenting accross different frames is not supported).

How can i bypass this eception. I dont know how to set the option you mention.

Thanks in advance, i hope you can help me.


PS i tried to reach a couple of days ago sending you an e-mail.

Christopher Deckers replied on Thu, 2008/11/06 - 7:26am

Hi Dimoklis,

I just checked and your e-mail actually ended up in my spam folder... I will respond by e-mail then.



Luis Fernando S... replied on Thu, 2009/01/15 - 10:13am

Hi there,


I have the same problem as Dimokils, trying to embedded a JWebBrowser in a docking window.

I would like your advice, if you don't mind.



Christopher Deckers replied on Thu, 2009/01/15 - 10:44am in response to: Luis Fernando Salazar Garcia

Hi Luis,

The exception that Dimoklis had could be bypassed by using an option in the constructor:

new JWebBrowser(JWebBrowser.destroyOnFinalization());

This allows the component to not be destroyed immediately when removed, but on finalization (when the garbage collector runs). Nevertheless, the technique used does not allow that to work accross windows, so you cannot move the native component from window to window. Unfortunately, this is what a docking framework is usually doing.



Luis Fernando S... replied on Sat, 2009/01/31 - 3:19pm in response to: Christopher Deckers

Hi there


Thanks a lot Christopher, it works smoothly ^^.

 I will try to overwrite the undock button event to create the window by hand and create another JWebBrowser giving the illusion that im moving the component to another window.


Again, thanks a lot.

suraj chandran replied on Wed, 2009/02/04 - 12:40pm

Fortunately, I decided to make an architectural change (ditching this SWT_AWT bridge, but still using SWT), and the next version (0.9.4) really is more stable

But i still see in the code that you are doing SWT_AWT.new_Shell()?

Or am i looking at an older version.

Also I really dont understand how workaround the "in SWT you can't reparent a control" problem by using destroyOnFinalization. I see that you are adding in layeredPane....but...

Can you throw some light

suraj chandran replied on Wed, 2009/02/04 - 12:54pm

Also when i use replace:

final JWebBrowser webBrowser = new JWebBrowser();


final JWebBrowser webBrowser = new JWebBrowser(JWebBrowser.destroyOnFinalization());

the browser does nto come up at all...I mean the frame opens but it does'nt goto google or any site at all, the broser part is simly gray

I am using Win XP with JRE 6 update 12

Am i doing soemthing wrong

suraj chandran replied on Wed, 2009/02/04 - 1:08pm

I debugged a little and found out that it was because of

if(deferredDestruction != null && componentHierarchyProxying == null) {componentHierarchyProxying = true;


in NativeComponentWrapper. When I comment this code it seems to be working fine.

An yhelp Chris ..

suraj chandran replied on Wed, 2009/02/04 - 1:10pm

But it some places it still doesent work

dai xitrum replied on Tue, 2009/03/17 - 9:41am


I had the same problem with the webpage not showing up on one of my machine.

What you have to do is downgrade the JRE from update 12 to update 10.

Christopher Deckers replied on Fri, 2009/03/27 - 1:19pm in response to: dai xitrum


Native Swing 0.9.7 and previous do not cope well with update 10+.

Update 10 is a problematic release, but other versions (previous or later) should work fine with the new Native Swing 0.9.8.


Alexander Klein replied on Wed, 2009/04/01 - 8:40am



I have the same problem with Native Swing Version 0.9.8 and JRE 1.6.0_13.

 Any ideas ?

- Sascha

Christopher Deckers replied on Wed, 2009/04/01 - 10:21am in response to: Alexander Klein

Hi Sascha,

Which problem exactly?


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.