Skip to main content

Initially-hidden applet reports zero dimensions on startup using b12

1 reply [Last post]
nhurst
Offline
Joined: 2006-05-05

When an APPLET tag is in a hidden SPAN/DIV tag which is then displayed dynamically after the page loads, the applet's getWidth() and getHeight() methods return 0.

This has consequences for applets that require the applet dimensions to implement double-buffering schemes, for example. The problem affects IE6 SP1, but not Firefox. The problem does not occur when using OBJECT/EMBED tags instead of the APPLET tag.

I've seen the problem in all the Update N builds I've tested, including b12. It did not arise in previous jre5 or 6 release versions. See attached basic applet and HTML file to test the problem.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
kbr
Offline
Joined: 2003-06-16

Thanks for the report and the concise test case. I've filed 6670162 to track this issue. It should show up in the Sun bug database in a few days.

In some circumstances (including having the applet tag hidden, but including dynamically generating the HTML of the applet tag) IE sends our ActiveX control several bogus width and height values. The logic attempting to deal with this was rewritten in the new Java Plug-In to simplify a huge bunch of hacks, and the new heuristics have been one problem area in the new plug-in. We'll try to figure out a way to be compatible with the old behavior.

Note though that your applet really should handle this case better by watching for resize events. The best we will be able to do is to report the width and height from the applet tag. On high-DPI displays, though, IE actually scales up the visible region of the applet by a certain percentage. This means that your applet will think it's 400x300 in init() and start() when in fact it's 500x375 when finally made visible. We don't know the 500x375 values until IE hands them to us, which is when the applet is made visible. But for other compatibility reasons we have to start the applet before it's made visible.