Resizing an applet when the browser is resized.

I have seen several posts on this topic in the archives, but haven't been able to get my applet to resize when the browser is resized.

Is there an official example on how to do this?

My applet is not the only element on the page. I tried setting the height and width to 100%, but this had no effect.

I have also copied a "resize" routine, which is executed by onLoad and onResize. This routine is getting executed, but the applet doesn't behave.

To get this method to work, I had to explicitly code the OBJECT tag in order to supply and ID that could be referenced by JavaScript, and I explicity set the MAYSCRIPT variable. I could not find out how to do this using the jsp:plugin tag.

No joy... my applet still doesn't respond, I am testing using IE 5.5.

Here is my code, note that I have tried several methods on the object:

<SCRIPT LANGUAGE="JavaScript">

function resize() {

var w_newWidth,w_newHeight;

var w_maxWidth=1600, w_maxHeight=1200;

if (navigator.appName.indexOf("Microsoft") != -1) {

w_newWidth=document.body.clientWidth;

w_newHeight=document.body.clientHeight;

} else {

var netscapeScrollWidth=15;

w_newWidth=window.innerWidth-netscapeScrollWidth;

w_newHeight=window.innerHeight-netscapeScrollWidth;

}

if (w_newWidth>w_maxWidth)

{

w_newWidth=w_maxWidth;

}

if (w_newHeight>w_maxHeight)

{

w_newHeight=w_maxHeight;

}

document.all.topologyApplet.resize(w_newWidth,w_newHeight);

document.all.topologyApplet.setSize(w_newWidth,w_newHeight);

//document.all.topologyApplet.sizeApp(100,100);

window.scroll(0,0);

}

window.onResize = resize;

window.onLoad = resize;

</SCRIPT>

<!-- START TOPO APPLET SECTION -->

<!-- <div id="topo" style="margin:10 0 10 0"> -->

<div id="topo" >

<table width="1000" border="0" cellspacing="0" cellpadding="3">

<tr>

<td >

<OBJECT id="topologyApplet"

classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"

width="644" height="446"

codebase="http://java.sun.com/products/plugin/1.2.2/jinstall-1_2_2-win.cab#Version=1,2,2,0">

<PARAM name="java_code" value="com.topology.applet.TopologyApplet">

<PARAM name="java_archive" value="applet/topology.jar">

<PARAM name="type" value="application/x-java-applet;version=1.3">

<PARAM name="subnetName" value="<%=sname%>">

<PARAM name="jsessionid" value="<%=session.getId()%>">

<PARAM name="groupName" value="<%=gname%>">

<PARAM name = "scriptable" value = "true" >

<PARAM name="MAYSCRIPT" value="true">

<COMMENT>

<EMBED type="application/x-java-applet;version=1.3"

width="644" height="446"

pluginspage="http://java.sun.com/products/plugin/"

java_code="com.lane15.console.topology.applet.TopologyApplet"

java_archive="applet/topology.jar"

id="topologyApplet"

jsessionid="<%=session.getId()%>" subnetName="<%=sname%>" groupName="<%=gname%>"

>

<NOEMBED>

</COMMENT> Plugin not supported

</NOEMBED>

</EMBED>

</OBJECT>

</td>

</tr>

</table>

[3484 byte] By [john060257] at [2007-9-26 2:58:31]
# 1

Additional information....

In the resize method of my applet, I inserted some code to print the resize values to the Java console.

What I am finding is interesting... My applet gets resized to the size of the browser window, and then gets sized back to the original setting from the HTML page.

Does anyone have any ideas where this second resize may be coming from, and how I might either disable it or have my desired resize happen "last"?

Thanks for any pointers.

john060257 at 2007-6-29 10:53:31 > top of Java-index,Desktop,Deploying...
# 2

Here's some more information... If put the following code into the applet itself, I can make the applet resize properly (in simple terms, once setSize has been called I use those values), but I can clearly see that the plugin container itself is still being drawn in the original size.

How can I tell the plugin container to resize?

boolean m_Override = false;

int m_widthOverride = 0;

int m_heightOverride = 0;

public void resize( Dimension d )

{

if (m_Override = true)

{

d.height = m_heightOverride;

d.width = m_widthOverride;

}

System.out.println("Resize " + d.toString());

super.resize(d);

}

public void resize( int width, int height )

{

if (m_Override = true)

{

height = m_heightOverride;

width = m_widthOverride;

}

System.out.println("Resize " + width + " " + height);

super.resize( width,height );

}

public void setSize(int width, int height)

{

m_Override = true;

m_widthOverride = width;

m_heightOverride = height;

System.out.println("setSize " + width + " " + height);

super.setSize(width,height);

validate();

}

john060257 at 2007-6-29 10:53:31 > top of Java-index,Desktop,Deploying...
# 3

Yet some more info.... I revisited setting the size of the applet in percentages, and I discovered that this does work AS LONG AS THE APPLET IS NOT EMBEDDED IN A <TABLE>. Even if the table's width, and the <td> width is set in percentages, the applet will not appear at all.

So it looks like the percentage approach is fine, as long as the applet "stands alone" on the page. Not exactly what I wanted.

john060257 at 2007-6-29 10:53:31 > top of Java-index,Desktop,Deploying...