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
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workkloads.

Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

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

  • Docker Base Images Demystified: A Practical Guide
  • How Large Tech Companies Architect Resilient Systems for Millions of Users
  • The Modern Data Stack Is Overrated — Here’s What Works
  • Java’s Next Act: Native Speed for a Cloud-Native World
  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.1K 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
Oops! Something Went Wrong

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

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

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 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!