-1

I need to insert an applet into a table-row and get that table-row's height to dynamically resize according to the browser's window size. If I put fixed values for width & height in the td-tag, it shows the applet fine, but I need to be able to resize this according to the client's size capabilities, so using fixed sizes is not the answer.

The snippet below should illustrate where my problem lies:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JavaAppletTest </title>
    </head>

    <body bgcolor="#6f6f6f" >
        <table border="0" cellspacing="0" cellpadding="0" width="100%" >
            <tr valign="top">
                <td><img src="images/myheader.jpg" alt="myheader.jpg"></td>
                <td><img src="images/mylogo.jpg" alt="mylogo.jpg"></td>
            </tr>
            <tr >
                <td colspan="2" >
                    <object codetype="application/java"
                             classid="java:applets.MyTestApplet.class">
                        <param name="codebase" value="." >
                        <param name="archive" value="MyTestApplet.jar" >
                        <param name="code" value="applets.MyTestApplet" >
                    </object>
                </td>
            </tr>
        </table>
    </body>
</html>

What do I need to do to make the row-dimensions dynamic?

[edit] jitter's answer indicates a possible solution. I also need to adjust the relevant sizes when the user resizes the window: what event & how do I do that?

slashmais
  • 7,069
  • 9
  • 54
  • 80

1 Answers1

1

I suggest using javascript to write the object/embed tag and calculating the size dynamically.

This should do the trick basically but be aware of the fact that getting the correct width and size can be tricky. I refer you to Finding the size of the browser window.

...
<head>
...
  <script type="text/javascript">
    window.onresize = function(event) {
      document.getElementById('myobject_tag').height = window.innerHeight;
      document.getElementById('myobject_tag').width = window.innerWidth;
    }
  </script>
</head>
...
<body bgcolor="#6f6f6f">
  <table border="0" cellspacing="0" cellpadding="0" width="100%">
    <tr valign="top">
      <td><img src="images/myheader.jpg" alt="myheader.jpg"></td>
      <td><img src="images/mylogo.jpg" alt="mylogo.jpg"></td>
    </tr>
    <script type="text/javascript">
      var height = window.innerHeight;
      var width = window.innerWidth;
      document.write(
        '<tr><td colspan="2"><object id="myobject_tag"\n' +
        'codetype="application/java"\n' +
        'classid="java:applets.MyTestApplet.class"\n' +
        'width="' + width + '"\n' +
        'height="' + height + '"\n>' +
        '<param name="codebase" value=".">\n' +
        '<param name="archive" value="MyTestApplet.jar">\n' +
        '<param name="code" value="applets.MyTestApplet">\n' +
        '</object></td></tr>'
      );
    </script>
  </table>
...
jitter
  • 53,475
  • 11
  • 111
  • 124
  • Thanks, your script works 100% (on firefox). Now I need to just adjust it to make the table fit. – slashmais Oct 11 '09 at 07:29
  • Also: I need to adjust the sizes when the user resizes the window. Is there some kind of event I can use & how? ( I'm new to Java/web development - normally do C++, and let no-one tell you it's easy to pickup Java if you know C++, it is not: Java/web-dev is much more diverse/complex.) – slashmais Oct 11 '09 at 07:42
  • enhanced code snippet. note javascript in head and the id tag in the object tag – jitter Oct 11 '09 at 08:06
  • Thanks - exactly what I needed. (Got the table-size fitting nicely in the meantime) :-) – slashmais Oct 11 '09 at 08:23