July 23, 2004

Permalink Safari Will Not Resize Java Applets

I am stuck! Maybe somebody will run across this and have a suggestion or at least feel my pain.

I am trying to get a web application to work on Safari, the Mac OS X browser of choice. One of the things I need to happen is for the multiple applets on the page to resize when the browser is resized.

In Internet Explorer, this is done beautifully by simply setting the height and width of the applet initially to 100%. On Mozilla-based browsers, it takes a little more work but I found an article that got it working for me. The trick is to call into the applet and have it redraw itself. It works good but then the applet seems to have trouble staying painted unless I keep calling this routine every few seconds. Suck.

But on Safari, nothing works! I have tried everything I can think of. Setting the applet size to 100% doesn’t work. It ends up treating 100% as 0 pixels. I tried the Mozilla-trick and that didn’t work. I tried adjusting the style.width property of the object. Nothing. You can’t adjust it once its drawn.

So my conclusion is that Safari doesn’t support this. Safari just delivered LiveConnect support in the last release (1.2) so its not impossible that they just don’t support this. About my only hope now is to simply unload and reload the frame with the applet on resize. The bad news is that Safari can’t seem to figure out the height of an IFRAME. It keeps returning negative numbers.

On Apple’s web site they say “the best browser on any platform” — not quite. Internet Explorer may have it share of troubles but its still my web development platform of choice because things just work.

UPDATE: The solution for Safari 1.2 or less is to reload the window or frame and set the size of the applet on load to the new size. I loaded Safari 1.3 as well as Safari 2.0 and found that applets now support height and width values of 100% so you finally get dynamic resizing.

Posted: 2004-07-23 at 22:57 MST in Geek
Tags: apple java
Related Posts with Thumbnails