The problem I was trying to solve was to resize applets when the browser changes size,
so as to always fill the total displayed area of the browser.
Googling I found an article from javaworld - Resize applets within browser frames.

I soon found out that the solution doesn't work on either Internet Explorer 6 or Netscape 7.1.
The key problem is that applet.setSize() method doesn't actually do anything!
So I did a bit of digging around and found a simpler solution.

The code shown below creates an applet with the same size as the browser window.
Whenever the browser changes size the applet is resized dynamically. This is
achieved through the resize() method defined in Javascript. This method is
invoked onLoad and onResize. The code works for the recent versions of
Internet Explorer & Netscape browsers.


    
    Resizable Applet Demo
    
    
        
        
    

The two lines:

document.myApplet.width = width;
document.myApplet.height = height;

are enough to change the width and height of the applet.
Remember to name the applet and refer to it by name.

Footnote: EU has proposed a simpler solution to the original problem which is to set the width and height to 100% in the applet tag. And that works for the problem I proposed. Thanks for the solution EU!

There are a few additional value to the original proposed solution over the new solution which are:

  • Finer control over the size of the applet, so for example you can say that the width leaves 20 pixels on both sides, but the height doesn't etc.
  • Ability to control the size of the applet from the applet itself. This is a big plus as in one project I am working we have a need to re-size the applet from within the applet. Now we can do it by calling a Javascript method from the applet.