How do I run Swing Applets in a Browser?

John Zukowski

While technically possible to use the Swing components in any Java 1.1-based browser, realistically is another story. The JAR file of Swing classes is approximately 2 MB, which would be required to be downloaded every time a user needed to run the applet. Unless you required your users to manually install the classes locally, this isn't usually a realistic option. The best alternative is to have your users install the Java Plug-in (http://java.sun.com/products/plugin/) which comes with the Swing classes included. Of course, this then requires you to modify your HTML to ensure the browser uses the Plug-in. (You'll need the HTML Converter, as described in How can I make my JApplet automatically download the Java Plug-in needed to run Swing applets? .)

If you wish to support users not having the Plug-in, you would need to place the swingall.jar file from the Swing release on your web server. Otherwise, its just use JApplet as the class to subclass for your applets, instead of Applet.

If you do decide to place swingall.jar on the server, the following <APPLET> tag will work when your applet subclasses JApplet, assuming you associate to the right applet and use the size you desire:

<applet code=JTest width=300 height=300>
  <param name="archive" value="swingall.jar">