Skip to main content

Applet Dragging in Linux

Posted by cayhorstmann on September 15, 2008 at 8:17 AM PDT

Being a Linux user, I watched those applet dragging demos with envy when they only worked on Windows. When the release candidate of JDK 6 update 10 (now there is a product name only a mother could love...) came out, I was eager to try it out on Linux. Initially, I was held back by a factor entirely beyond my control, i.e. my cluelessness and unwillingness to read the docs. Thanks to Aaron Houston and Ken Russell for helping me out. Here are the steps:

  1. First off, you need to make sure that the new functionality is actually enabled. The Linux installer for JDK 6 update 10 doesn't do that for you. You must remove the symlink to the old plugin from your plugins directory (such as ~/.mozilla/plugins) and add a symlink to /path/to/jdk1.6.0/jre/lib/i386/libnpjp2.so
    For example, ln -s ~/jdk1.6.0/jre/lib/i386/libnpjp2.so ~/.mozilla/plugins/libnpjp2.soThis is explained here.
  2. The applet drag gesture is Alt + click, which unfortunately conflicts with the Gnome gesture to drag a window. As explained here, you can write code in your applet to have a different drag gesture, but that seems daft—how are you supposed to know what goes on with the window manager of the person viewing your applet? Maybe Sun could have done a better job here and identify suitable gestures for each platform? At this point, the easiest way around the problem is to reconfigure Gnome. Select System → Preferences → Window, then pick some other key than Alt for window dragging:

    Screenshot-Window Preferences.png
  3. Finally, keep in mind that this doesn't work automatically for all applets. You need to go to the applet code and add a parameter<param name="draggable" value="true">Try it out: Point your browser here and use Alt+Drag to move the applet anywhere you like:
    Screenshot-Draggable-Applet.png

Comments

IANAD ("i am not a developer"), just a java fan who does some minor tweaking and drag-n-drop programming in netbeans, so take my testimony as suspect. anyway, after several weeks of failure i was able to get the draggable applet to work in ubuntu heron 8.04 with jdk6u10-b33 by following Cay's advice. the trick seems to be the libnpjp2.so plugin, by copying or symbolic link, in the $HOME/.mozilla/plugins directory. i'm not even sure i had to remove the old plugin (libjavaplugin_oji.so), as the draggable feature seems to work even after i put libjavaplugin_oji.so back in the plugins dir.

Apparently "xulrunner-1.9-javaplugin.so" is the magic word, this makes the new applets work in firefox 3 in ubuntu intrepid: sudo update-alternatives --install /etc/alternatives/xulrunner-1.9-javaplugin.so xulrunner-1.9-javaplugin.so /usr/lib/jvm/java-6-sun/jre/lib/i386/libnpjp2.so 50 sudo update-alternatives --config xulrunner-1.9-javaplugin.so and select the libnpjp2.so option

Anyone care to share how to get this to work in Ubuntu Intrepid or Hardy? I've used update-alternatives and so forth, and the libnpjp2.so is installed to the right place (/usr/lib/firefox/plugins), and I remove the libjavaplugin.so, but still draggable applets and jnlp applets don't work. In particularly I've been testing these applets: https://scenegraph-demos.dev.java.net/demo-applets.html Java 1.6 update 10 build 33 is installed. I also downloaded the latest from the sun site and used update-alternatives to point to the right .so and it didn't work. I also fixed the plugins in /usr/lib/mozilla/plugins too, no dice.

>how are you supposed to know what goes on with the window manager of the person viewing your applet? ...At this point, the easiest way around the problem is to reconfigure Gnome. You could also create a "dragable area" e.g the controls on top of your applet with UI telling the user that he can drag it (without additional shortcuts). The draggable applet sample on the early acces page does it this way. Shortcuts are only helpful for powerusers anyway ;)

Am not interested in having multiple versions of Java, mixing 32bit and 64bit libraries cause a whole bunch of problems in browsers. And come one, 64bit CPU's have been mainstream since the year 2000 now.

@mrmorris it works on 64bit linux too.... who says you have to run 64bit software on 64bit systems.

Let's set it straight that this is for the 32bit Linux users, not the unfortunate 64bit users.