Applet of the Week!

I've been in touch with NetBeans user Corey Hunt over the last few days who was working on creating an applet that would make use of the NetBeans Visual Library. At first I didn't think it would be possible at all, but David Kaspar, the library's creator, assured me that it was. There were several problems to solve first, though. Some general guidelines follow:

  1. Work through the applet tutorial to understand how applets are constructed in NetBeans IDE.

  2. Next, add the Visual Library JAR and the Utilities JAR to your Java application and then integrate the Visual Library code into the applet. For example, this is Corey's code that does the job:

    public class AppletRes extends JApplet {
        private DemoGraphScene scene = new DemoGraphScene();
        private javax.swing.JScrollPane jScrollPane1;
        /\*\* Initializes the applet AppletRes \*/
        public void init() {
            try {
                java.awt.EventQueue.invokeAndWait(new Runnable() {
                    public void run() {
                        jScrollPane1 = new javax.swing.JScrollPane();
                        add(jScrollPane1, java.awt.BorderLayout.CENTER);
            } catch (Exception ex) {

  3. Then, once you've got your applet working, before attaching it to the web application (which is explained in the tutorial above), you need to make sure that the content of the two JARs (i.e., the Visual Library JAR and the Utilities JAR) are wrapped into the JAR that contains the applet. Here's the Ant target, something like this is needed in your build.xml file:

    <target name="-post-jar">
        <jar update="true" destfile="${dist.jar}">
            <zipfileset src="${libs.swing-layout.classpath}"/>
            <zipfileset src="${}"/>
            <zipfileset src="${}"/>

  4. At this point you have your JAR containing your applet, plus the content of the three JARs above. Now that JAR can be added to the web application, but it also needs to be signed. Follow the steps described here, which pretty much describes everything, and is a blog entry I'd forgotten having ever written, actually, until Corey pointed me back to it.

And that's about it! Corey sent me a link to the result. Below you see his face (yes that's Corey), which can be moved around, it can be zoomed in/out, and the label below the pic can be edited. And everything you see below is in an applet:

It is the first time that I've seen the Visual Library API alive and kicking on the web. In his final note on the above, Corey writes: "Like I said, not much, but it represents a lot of gained knowledge and I am pretty stoked. Now, I am off to add functionality." Here's hoping he'll tell me when he gets to the next stage so I can share it here!


I just wanted to let everyone know that you don't need to zip/jar everything up into one JAR for this to work as an applet. You can reference the JAR files using the archive attribute which may contain a common delimited list of JAR files. That helps surpass any META-INF and manifest issues were entries needed which may otherwise be overwritten.

Posted by Wade Chandler on February 21, 2008 at 01:07 AM PST #


"common delimited" should be "comma delimited"

Posted by Wade Chandler on February 21, 2008 at 01:08 AM PST #

This is actually the code that did it.

<target name="-post-jar" depends="Jarsigner">
<jar update="true" destfile="${dist.jar}">
<zipfileset src="${libs.swing-layout.classpath}"/>
<zipfileset src="${}"/>
<zipfileset src="${}"/>
<jar update="true" destfile="${dist.dir}/sTestApplet.jar">
<zipfileset src="${libs.swing-layout.classpath}"/>
<zipfileset src="${}"/>
<zipfileset src="${}"/>

I had to add the jars to the signed jar as well. Thanks for posting me. My mom will think I'm famous :)

Posted by Corey Hunt on February 21, 2008 at 01:15 AM PST #

I have no idea what any of this means....but, I think Corey is, indeed, famous. Of course, I am also his Mom.

Posted by ann laurence on February 21, 2008 at 02:01 AM PST #

Wow, great job. Sorry Wade got all bummed out.
Wade, do you need a hug?

Posted by Benjamin Rew on February 21, 2008 at 02:45 AM PST #

This is old but a try is worthy i think\^\^
I have signed (following the tutorial) and added required targets (as Corey depicted) for my VL Applet but it doesn't work. The best case i have until now is just to see the applet's window,nothing more. If you can please send me in my e-mail a piece of code that works (or here).

Posted by Dimoklis Despotakis on February 08, 2010 at 01:57 AM PST #

Post a Comment:
  • HTML Syntax: NOT allowed

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.


« April 2014