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.)


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

Hi Christopher,


if I use

new JWebBrowser(JWebBrowser.destroyOnFinalization());

I don't see the Webbrowser with jre1.6.0_13 and Natve Swing 0.9.8 - just a grey area.

In the statusbar, it seems that the content page will be loaded, but nothing will be displayed.

If I use the same Native Swing but with jre 1.6.0_06 it works.



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

> I don't see the Webbrowser with jre1.6.0_13 and Natve Swing 0.9.8 - just a grey area.

Indeed. I think I said something incorrect, that 0.9.8 would work with Java 6 update 12+.

In fact, it works with all versions except Java 6 update 10 to 13. Java 6 update 14 works fine.


cddddd bb replied on Thu, 2009/04/23 - 3:20am

Hi Christopher : I usr your DJ Natve Swing 0.9.8 (" JFlashPlayer") in windows that is run , very ok but in linux (gtk2.1 ,jdk1.7 ) that have the question: can you help me ?-------------> NativeSwing: NativeSwing: (Gecko:4939): Gtk-CRITICAL **: gtk_window_group_remove_window: assertion `window->group == window_group' failed ------------------> at$BlockDataInputStream.peekByte( at at at at$ Failed messaging: NativeComponent$CMN_destroyControl()

Christopher Deckers replied on Thu, 2009/04/23 - 9:53am in response to: cddddd bb


The GTK warning you see is a bug with SWT. I would recommend you vote for it here.

For some reason, your connection to the native component dies, but it is hard to tell why... It could be the version of the browser on that machine that is causing some problem. I doubt that the GTK warning is the root cause because as far as I know it only shows a message and has no effect. I may be wrong though.

If you want to continue this discussion and eventually investigate further, please contact me by e-mail at: chrriis (at) nextencia (dot) net

Hope this helps,

cddddd bb replied on Thu, 2009/04/23 - 8:19pm

Dear Christopher Deckers appreciate your quick response !!! i dont known ,what can i do now!

muruganandan pa... replied on Thu, 2009/06/04 - 6:25am

Hi Chris,

we are facing some problem while loading swf file with your component, we use DJ Native Swing 0.9.8, java 1.6.0_13, windows XP

We use your component to load and communicate(through java) swf files which have more than two swf inside it

Our Application(java) needs to communicate with swf file to load specific external swf file(s)


Loading swf files inside swf works fine before integrating with java application

When we load the swf file inside java application, it won't works.....pls help


Christopher Deckers replied on Thu, 2009/06/04 - 12:47pm in response to: muruganandan palanisamy

Hi Muruganandan,

I am not sure which problem you have. But one thing is for sure, Java 6u10 to u13 are problematic releases. Use Java 6u14 or earlier releases than 6u10.

If you wish to continue investigating further, please you the DJProject forums on SourceForge or contact me by e-mail.



steve sloan replied on Thu, 2009/07/30 - 3:54pm


Hi Chris,


The grayed out webbrowser when you have the JWebBrowser.destroyOnFinzlization occurs in java 1.6.14

 // code

JFrame webFrame = new JFrame();



if i remove the destronOnFinizalization arg it works.


steve sloan replied on Thu, 2009/07/30 - 3:57pm


// sorry typo in comment, code is correct and not working in java1.6.14





P.S still a very cool library



Christopher Deckers replied on Fri, 2009/07/31 - 5:51am

Hi Steve,

For DJ Native Swing to work with Java 6u14, you need to download the 0.9.9 preview version:

Hope this helps,

steve sloan replied on Fri, 2009/07/31 - 9:53am


no joy.




Windows XP - DJNativeSwing-SWT-0-9-8

steve sloan replied on Fri, 2009/07/31 - 10:06am



It might be some other jar in my project. A simple program seems to be working fine.

steve sloan replied on Fri, 2009/07/31 - 11:00am



Finally got it.  If you open a JFrame (even for non-DJNative gui) before calling  the browser will not render (even if you call before trying to create/open browser).  Per your comment i put this call on fist line of main and it started working

Vitor Pelizza replied on Thu, 2009/08/20 - 11:50am

Hi Chris,

 I`m having some trouble to open swf files using the JFlashPlayer. I noticed it just works if the flash with activeX (for internet explorer) is installed. On another case, I installed this version of flash player but it doesn`t work too. I guess it`s because the flash version overriding, but I`m not sure yet.

 What exactly i have to install for it get working? Is there some way to embed the flash player in my application and use that player?



Xu Kim replied on Sun, 2010/05/09 - 10:54pm

Hi Chris,

  I have a problem ,when I remove the JWebBrowser from my panel ,then I add an JWebBrowser again ,there will have an problem "a native component cannot be removed then re-added to a component hierachy" ,why?

Christopher Deckers replied on Mon, 2010/05/10 - 1:45am in response to: Xu Kim


The native component is automatically destroyed when it is removed, which is why you cannot re-add it. Nevertheless, you can tell the native component to not automatically destroy in which case you can remove it and re-add it later. For this, add the option that is specified in the error message, something like:
JWebBrowser wb = new JWebBrowser(JWebBrowser.destroyOnFinalization());

For further questions, please use the help forum.

Hope this helps,

Divya A S replied on Wed, 2010/07/21 - 1:46am in response to: Christopher Deckers

Hi , I am trying to integrate JWebBrowser in a javafx application.The browser is getting rendered but the web page portion is altering on mouse movements.Not able to resize the frame also.Pls advice. Thanks,

Christopher Deckers replied on Fri, 2010/07/23 - 1:49pm in response to: Divya A S


JavaFX does not properly handle AWT components, most notable the Canvas component. DJ NativeSwing requires that so unless this bug is fixed in JavaFX (and I don't think anyone at Sun/Oracle is working on that), it is not possible to integrate a web browser in JavaFX using my library.

Hope this helps,

Comment viewing options

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