I have a java applet that is embedded in html using the object-ment-embed
method. I would like to resize the applet whenever the browser window is resized. I have found solutions around the internet, but they all work based on the deprecated applet
tag.
Also, when trying a setSize()
call on my embed
element in FireBug, it will resize the content of the applet, but not the applet viewport. That is, the area of the display that is given over to java does not change.
Current code looks something like this:
<object
id='MyApplet1'
width='300' height='200'
classid='clsid:XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'
codebase='.6.0/jinstall-6-windows-i586.cab#Version=1,6,0,0'>
<param name='type' value='application/x-java-applet;version=1.6'>
<param name='scriptable' value='false'>
<param name='codebase' value='foo'>
<param name='code' value='bar'>
<param name='archive' value='baz'>
<param name='arg1' value='A'>
<param name='arg2' value='B'>
<ment>
<embed
id='MyApplet2'
width='300' height='200'
pluginspage='.html#download'
type='application/x-java-applet;version=1.6'
scriptable='false'
codebase='foo'
code='bar'
archive='baz'
arg1='A'
arg2='B'>
<noembed>
</noembed>
</embed>
</ment>
</object>
<script type="text/javascript">
function resize() {
min_width = 300;
min_height = 200;
frame_width = 0;
frame_height = 0;
if(parseInt(navigator.appVersion) > 3) {
if(navigator.appName=='Netscape') {
frame_width = window.innerWidth;
frame_height = window.innerHeight;
}
if (navigator.appName.indexOf('Microsoft') != -1) {
frame_width = document.body.offsetWidth;
frame_height = document.body.offsetHeight;
}
}
frame_width *= 0.78;
frame_height *= 0.78;
applet_width = frame_width > min_width ? frame_width : min_width;
applet_height = frame_height > min_height ? frame_height : min_height;
document.getElementById('MyApplet1').setSize(applet_width, applet_height);
document.getElementById('MyApplet2').setSize(applet_width, applet_height);
}
window.onResize = resize;
window.onLoad = resize;
</script>
I have a java applet that is embedded in html using the object-ment-embed
method. I would like to resize the applet whenever the browser window is resized. I have found solutions around the internet, but they all work based on the deprecated applet
tag.
Also, when trying a setSize()
call on my embed
element in FireBug, it will resize the content of the applet, but not the applet viewport. That is, the area of the display that is given over to java does not change.
Current code looks something like this:
<object
id='MyApplet1'
width='300' height='200'
classid='clsid:XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'
codebase='http://java.sun./update/1.6.0/jinstall-6-windows-i586.cab#Version=1,6,0,0'>
<param name='type' value='application/x-java-applet;version=1.6'>
<param name='scriptable' value='false'>
<param name='codebase' value='foo'>
<param name='code' value='bar'>
<param name='archive' value='baz'>
<param name='arg1' value='A'>
<param name='arg2' value='B'>
<ment>
<embed
id='MyApplet2'
width='300' height='200'
pluginspage='http://java.sun./products/plugin/index.html#download'
type='application/x-java-applet;version=1.6'
scriptable='false'
codebase='foo'
code='bar'
archive='baz'
arg1='A'
arg2='B'>
<noembed>
</noembed>
</embed>
</ment>
</object>
<script type="text/javascript">
function resize() {
min_width = 300;
min_height = 200;
frame_width = 0;
frame_height = 0;
if(parseInt(navigator.appVersion) > 3) {
if(navigator.appName=='Netscape') {
frame_width = window.innerWidth;
frame_height = window.innerHeight;
}
if (navigator.appName.indexOf('Microsoft') != -1) {
frame_width = document.body.offsetWidth;
frame_height = document.body.offsetHeight;
}
}
frame_width *= 0.78;
frame_height *= 0.78;
applet_width = frame_width > min_width ? frame_width : min_width;
applet_height = frame_height > min_height ? frame_height : min_height;
document.getElementById('MyApplet1').setSize(applet_width, applet_height);
document.getElementById('MyApplet2').setSize(applet_width, applet_height);
}
window.onResize = resize;
window.onLoad = resize;
</script>
Share
Improve this question
asked Dec 17, 2008 at 16:59
JorenkoJorenko
2,6642 gold badges22 silver badges27 bronze badges
1
- does your resize function get called? (e.g. where is the error so far?) – scunliffe Commented Dec 17, 2008 at 17:06
2 Answers
Reset to default 4Try replacing these lines:
document.getElementById('MyApplet1').setSize(applet_width, applet_height);
document.getElementById('MyApplet2').setSize(applet_width, applet_height);
with:
document.getElementById('MyApplet1').style.height = applet_height + "px";
document.getElementById('MyApplet1').style.width = applet_width + "px";
document.getElementById('MyApplet2').style.height = applet_height + "px";
document.getElementById('MyApplet2').style.width = applet_width + "px";
Why don't you use percentage width and height. I usually use the following code for my applets:
<applet codebase="http://localhost:89" archive="npaxet?version=0.0.1.28" code="main.NPaxet.class" width=100% height=90%>\
<PARAM NAME="thumbnailUrl" VALUE="http://localhost:89/thumbnail?seriesid=%s">
<PARAM NAME="diUrl" VALUE="http://localhost:89/di?imageid=%d">
<PARAM NAME="seriesCount" VALUE="11">
...
</applet>