DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Micro Frontends With Example
  • Automated Application Integration With Flask, Kakfa, and API Logic Server
  • Implementing Real-Time Datadog Monitoring in Deployments
  • What Is API-First?

Trending

  • A Hands-On ABAP RESTful Programming Model Guide
  • A System Cannot Protect What It Does Not Understand
  • Multi-Scale Feature Learning in CNN and U-Net Architectures
  • How to Format Articles for DZone
  1. DZone
  2. Software Design and Architecture
  3. Integration
  4. DJ NativeSwing - reloaded: JWebBrowser, JFlashPlayer, JVLCPlayer, JHTMLEditor.

DJ NativeSwing - reloaded: JWebBrowser, JFlashPlayer, JVLCPlayer, JHTMLEditor.

By 
Christopher Deckers user avatar
Christopher Deckers
·
Mar. 12, 08 · News
Likes (0)
Comment
Save
Tweet
Share
54.5K Views

Join the DZone community and get the full member experience.

Join For Free

Today's release of DJ Native Swing 0.9.4 greatly improves stability and brings new components: in addition to the JWebBrowser and JFlashPlayer, there is now the JVLCPlayer and the JHTMLEditor.
Here is a summary of what to expect when using this library.

 

1. Various native components

DJ Native Swing was designed to handle all the complexity of native integration, mainly in the form of components with a simple Swing-like API.

Here are some screenshots of several components in action (click to enlarge):

JWebBrowser:
JFlashPlayer:
JWebBrowser JFlashPlayer
JVLCPlayer:
JHTMLEditor:
JVLCPlayer JHTMLEditor

 

2. Simple API

First, we need to initialize the framework. This needs to happen before any feature is used. A common place for this call is the first line of the main():

public static void main(String[] args) {
NativeInterfaceHandler.init();
// Here goes the rest of the initialization.
}

Now, let's see how to create a JWebBrowser, with its URL set to Google's homepage:

JWebBrowser webBrowser = new JWebBrowser();
webBrowser.setURL("http://www.google.com");
myContentPane.add(webBrowser);

Note that we set a URL, but we could as well set the HTML text. The JWebBrowser also allows to execute Javascript calls, and we can even propagate notifications from custom pages to our Swing application.

Moving to a more practical example, we may want to be notified of URL change events or track window opening events, potentially preventing navigation to occur or open the page elsewhere. This is easily achieved by attaching a listener:

webBrowser.addWebBrowserListener(new WebBrowserAdapter() {
public void urlChanging(WebBrowserNavigationEvent e) {
String newURL = e.getNewURL();
if(newURL.startsWith("http://www.microsoft.com/")) {
// Prevent the navigation to happen.
e.consume();
} else {
// We can consume the event and decide to open this page in a tab.
}
}
public void windowWillOpen(WebBrowserWindowWillOpenEvent e) {
// We can prevent, add the URL to a tab, etc.
}
// There are of course more events that can be received.
});

Let's have a look at the JFlashPlayer:

JFlashPlayer flashPlayer = new JFlashPlayer();
flashPlayer.setURL(myFlashURL);

The JFlashPlayer can open local or remote Flash files, and files from the classpath; the latter being a general capability of the library by proxying files using a minimalistic web server.
Of course, the JFlashPlayer allows to retrieve and set Flash variables, and play/pause/stop the execution.

The JVLCPlayer and the JHTMLEditor are no exceptions to this simplicity: playlist can be manipulated in the VLC player, HTML can be set and retrieved from the HTML editor, etc.

There is also the possibility to integrate Ole controls on Windows, still with a simple Swing-like API. An example is provided in the library in the form of an embedded Windows Media Player.

 

3. Advanced capabilities

The library takes care of most common integration issues. This covers modal dialog handling, Z-ordering, heavyweight/lightweight mix (to a certain extent), invisible native components with regards to focus handling and threading.

Here are some more screenshots, showing a lightweight/heavyweight mix, and Z-ordering capability:

Component Mix 1

Component Mix 2

The demo application that is part of the distribution shows all the features along with the source code, so check it out!

 

4. Project info and technical notes

Webstart demo: http://djproject.sourceforge.net/ns/DJNativeSwingDemo.jnlp
Screenshots: http://djproject.sourceforge.net/ns/screenshots
Native Swing: http://djproject.sourceforge.net/ns
The DJ Project: http://djproject.sourceforge.net

The 0.9.4 version has a completely new architecture. It still uses SWT under the hood, but it does not use the SWT_AWT bridge anymore.

The JWebBrowser and browser-based components require XULRunner to be installed, except on Windows when using Internet Explorer.
The JVLCPlayer requires VLC to be installed.
The JHTMLEditor uses the FCKeditor.

 

5. Conclusions

This project finally brings all that is needed to make Java on the desktop a reality. A web browser, a flash player, a multimedia player, and even an HTML editor. So, what next?

Yes, what next? For that one, I am waiting for your feedback. So, what do you think? What are your comments and suggestions?

-Christopher

 

HTML Library Browser-based application Integration API code style Visible light communication

Published at DZone with permission of Christopher Deckers. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Micro Frontends With Example
  • Automated Application Integration With Flask, Kakfa, and API Logic Server
  • Implementing Real-Time Datadog Monitoring in Deployments
  • What Is API-First?

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook