Mixing Swing and Native Components
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.
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: http://djproject.sourceforge.net/ns/DJNativeSwingDemo.jnlp
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?
-Christopher
Screenshots: http://djproject.sourceforge.net/ns/screenshots
Native Swing: http://djproject.sourceforge.net/ns
The DJ Project: http://djproject.sourceforge.net
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)






Comments
Alexander Klein replied on Wed, 2009/04/01 - 10:50am
in response to:
Christopher Deckers
Hi Christopher,
sorry,
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.
-SaschaChristopher 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.
-Christopher
cddddd bb replied on Thu, 2009/04/23 - 3:20am
Christopher Deckers replied on Thu, 2009/04/23 - 9:53am
in response to:
cddddd bb
Hi,
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,
-Christopher
cddddd bb replied on Thu, 2009/04/23 - 8:19pm
muruganandan pa... replied on Thu, 2009/06/04 - 6:25am
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)
Problem:
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
---Muruganandan
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.
-Christopher
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();
webFrame.getContentPane().add(webFrame);
webFrame.show();
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
webFrame.getContentPane().add(webBrowser);
-s
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:
http://sourceforge.net/projects/djproject/files/nativeswing-preview/0.9.9-20090719/DJNativeSwing-SWT-0-9-9-20090719.zip/download
Hope this helps,
-Christopher
steve sloan replied on Fri, 2009/07/31 - 9:53am
no joy.
-s
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 NativeInterface.open() the browser will not render (even if you call NativeInterface.open 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?
thanks!
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
Hi,
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,-Christopher
Divya A S replied on Wed, 2010/07/21 - 1:46am
in response to:
Christopher Deckers
Christopher Deckers replied on Fri, 2010/07/23 - 1:49pm
in response to:
Divya A S
Hi,
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,
-Christopher