Skip to main content

DJ Native Swing 0.9.7 - Web Browser, Flash Player and more!

11 replies [Last post]
chrriis
Offline
Joined: 2003-11-17

DJ Native Swing allows to easily integrate some native components into Swing applications, and provides some native utilities to enhance Swing's APIs.

The main focus is the integration of a native Web Browser and Flash Player using a Swing-like API. Nevertheless, it also offers other useful components like a multimedia player (based on VLC), an HTML editor (using FCKeditor or TinyMCE) and a Syntax Highlighter.
All the threading issues and general integration headaches are handled automatically. It also allows to mix lightweight and heavyweight components without major visual problems.

Native Swing: http://djproject.sourceforge.net/ns
Screenshots: http://djproject.sourceforge.net/ns/screenshots
Webstart Demo: http://djproject.sourceforge.net/ns/DJNativeSwing-SWTDemo.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 distribution.

It uses SWT under the hood, and thus should work everywhere SWT allows to be placed inside a Swing component. To get the web browser to work on Linux, follow the FAQ on SWT's website (XULRunner may be required).
DJ Native Swing is licensed under LGPL and requires Java 5 or later.

Note that it is a sub-project of the DJ Project ( http://djproject.sourceforge.net ), which is a set of tools and libraries to enhance the user experience of Java on the Desktop.

This release adds XPCOM access for the JWebBrowser when using XULRunner, an additional editor implementation for the JHTMLEditor using TinyMCE and a Syntax Highlighter.

-Christopher

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
dieguete
Offline
Joined: 2009-03-10

The code is the following:

[code]
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import javax.swing.BorderFactory;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

import chrriis.common.UIUtils;
import chrriis.dj.nativeswing.swtimpl.NativeInterface;
import chrriis.dj.nativeswing.swtimpl.components.JWebBrowser;

/**
* @author Christopher Deckers
*/
public class SimpleWebBrowserExample extends JPanel {

public SimpleWebBrowserExample() {
super(new BorderLayout());
JPanel webBrowserPanel = new JPanel(new BorderLayout());
webBrowserPanel.setBorder(BorderFactory.createTitledBorder("Native Web Browser component"));
final JWebBrowser webBrowser = new JWebBrowser();
webBrowser.navigate("http://www.google.com");
webBrowserPanel.add(webBrowser, BorderLayout.CENTER);
add(webBrowserPanel, BorderLayout.CENTER);
// Create an additional bar allowing to show/hide the menu bar of the
// web
// browser.
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 4, 4));
JCheckBox menuBarCheckBox = new JCheckBox("Menu Bar", webBrowser.isMenuBarVisible());
menuBarCheckBox.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
webBrowser.setMenuBarVisible(e.getStateChange() == ItemEvent.SELECTED);
}
});
buttonPanel.add(menuBarCheckBox);
add(buttonPanel, BorderLayout.SOUTH);
}

/* Standard main method to try that test as a standalone application. */
public static void main(String[] args) {
UIUtils.setPreferredLookAndFeel();
NativeInterface.open();
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JFrame frame = new JFrame("DJ Native Swing Test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(new SimpleWebBrowserExample(), BorderLayout.CENTER);
frame.setSize(800, 600);
frame.setLocationByPlatform(true);
frame.setVisible(true);
}
});
NativeInterface.runEventPump();
}
}
[/code]

lorth
Offline
Joined: 2009-03-19

I have the same problem with flash player. It's linking problem. You have to include jar files and additional archives from lib folder (distributed with DJNS). I don't know how exactly. I'll post a note when I'll figure it out.

diox76
Offline
Joined: 2008-02-06

hi chrriss!

I'd like to ask you where can I download the chrriis.common package.

Thanks in advanced.

;)

yangju
Offline
Joined: 2009-10-20

Christopher:

We are looking at a Richtext html editor inside our applet which is implemented using Swing. I found your project which may fit our needs. But my concern is that the NativeInterface.open() call may not work well in our swing based applet. Is there anyway to use the html editor without using SWT? Could you let me know that if this is going to be a problem or is there any other ways to use the html editor in our applet? Our applet is launched from a web browser. We run jre 1.6.0.

Thanks.

rtmoran
Offline
Joined: 2009-10-13

Hi,

Platform : Debian Lenny + java6

I'm getting this "unresponsive script" warning:

--------
A script on this page may be busy...(...)

Script: http://127.0.0.1:54130/class/2/chrriis.dj.nativeswing.swtimpl.WebBrowser...
------

I see the following 27th line :

return window.document[movieName];

must be related with Linux UNC filenames. I suppose is a java programming problem but I would like to know if I could disable those warnings, maybe using about:config in the browser url.

Any tips?

Thanks

chrriis
Offline
Joined: 2003-11-17

Hi,

Sorry about the late reply.

The problem is that the wrong version of SWT is used. You need at least SWT 3.5M1 for this to work.
Note that the correct versions of the libraries can be found under the lib folder.

-Christopher

dieguete
Offline
Joined: 2009-03-10

With the example code, the browser window opens, but the next exception is shown

Failed to create chrriis.dj.nativeswing.swtimpl.components.NativeWebBrowser[1/1559649526]

Reason:
java.lang.RuntimeException:java.lang.reflect.InvocationTargetException
java.lang.reflect.InvocationTargetException
java.lang.NoSuchMethodError: org/eclipse/swt/browser/Browser.getBrowserType()Ljava/lang/String;

please, help...

dieguete
Offline
Joined: 2009-03-10

* removed *

Message was edited by: dieguete

illegolas
Offline
Joined: 2008-04-17

Hey chrriis,

I tried using this library for using HTML Editor and found it awesome.

But I could not find one thing that how I can get the caret position and how effectively I can use it in this editor to programmatically append some text at the caret position.

Thanks

chrriis
Offline
Joined: 2003-11-17

Hi,

> But I could not find one thing that how I can get the
> caret position and how effectively I can use it in
> this editor to programmatically append some text at
> the caret position.

This is not currently possible. At the moment, this component is a simple HTML editor where you set the HTML text, or get the current edited content. All the other actions are performed within the editor area and its toolbar.

Nevertheless, I will think about such API for potential inclusion in future releases.

Thanks a lot for your feedback!

-Christopher

illegolas
Offline
Joined: 2008-04-17

I think if you could do that then such API will make it more powerful in that case.

Thanks for the quick reply.