awt browser incompability

I'm doing an applet gui (pure AWT). I have a Canvas inside a ScrollPane. The canvas displays pictures or text of different sizes dynamically, so I reset its size before every paint() with setSize(), then validate(), then getParent().validate() to make sure the ScrollPane resets the scrollbars.

This works fine with the Netscape 6 browser, the scrollbars appear when needed, according to the size of the Canvas.

But it doesn't work with MS IE5: scrollbars don't appear. I fear a browser incompatibility! Suggestions anyone?

miguel

[572 byte] By [mjuteau2001] at [2007-9-26 1:55:38]
# 1

Hi.

In the Canvas, override

public Dimension getPreferredSize()

then call

theCanvas.invalidate();

and

theScrollPane.validate();

whenever the size changes.

Regards,

";-)

Ragnvald Barth

Software engineer

Ragnvald at 2007-6-29 3:09:46 > top of Java-index,Desktop,Core GUI APIs...
# 2
When I override getPreferredSize() in the Canvas, what code do I put in? Do u mean I should call invalidate() and scrollPane.validate() inside of getPreferredSize(), then call getPreferredSize() whenever the size changes?Thanks,miguel
mjuteau2001 at 2007-6-29 3:09:46 > top of Java-index,Desktop,Core GUI APIs...
# 3

Hi Miguel

I'm doing almost exactly this. I'm adding an array of objects (SimpleCanvas) which extends java.awt.Canvas into ScrollPane. SimpleCanvas can display Images and Text of different sizes dynamically. This works fine in AppletViewer (JDK1.3) But when I run it in browser, The images are not displayed in both IE 5.0 and Netscape 4.7.

You are able to see your applet in NS6 because NS6 directly comes with Java Plugin and IE does not.

Please email me when you solve this problem.

harshapr@comatindia.com

Regards,

Harsha

Here is the message on the java console:

<NETSCAPE 4.7 Java Console>

java.lang.NullPointerException

at sun.awt.windows.WToolkit.checkScrImage(Compiled Code)

at sun.awt.windows.WComponentPeer.checkImage(Compiled Code)

at java.awt.Component.checkImage(Compiled Code)

at java.awt.ImageMediaEntry.getStatus(Compiled Code)

at java.awt.MediaTracker.checkAll(Compiled Code)

at java.awt.MediaTracker.checkAll(Compiled Code)

at SimpleCanvas3.paint(Compiled Code)

at java.awt.Component.dispatchEventImpl(Compiled Code)

* at java.awt.Component.dispatchEvent(Compiled Code)

at java.awt.EventDispatchThread$EventPump.dispatchEvents(Compiled Code)

at java.awt.EventDispatchThread.run(Compiled Code)

at netscape.applet.DerivedAppletFrame$AppletEventDispatchThread.run(Compiled Code)

</NETSCAPE 4.7 Java Console>

<IE 5.0 Java Console>

java.lang.NullPointerException

at com/ms/awt/WToolkit.checkScrImage

at com/ms/awt/WComponentPeer.checkImage

at java/awt/Component.checkImage

at java/awt/ImageMediaEntry.getStatus

at java/awt/MediaTracker.checkAll

at java/awt/MediaTracker.checkAll

at SimpleCanvas3.paint

at com/ms/awt/WComponentPeer.doClearAndPaint

at com/ms/awt/WComponentPeer.paintNode

at com/ms/ui/windowmanager/PaintRequest.run

at com/ms/ui/windowmanager/RunnableMessage.run

at com/ms/awt/WSystemQueue.getMessage

at com/ms/awt/WEventQueue.getNextEvent

at java/awt/EventDispatchThread.run

</IE 5.0 Java Console>

harsha_pr at 2007-6-29 3:09:46 > top of Java-index,Desktop,Core GUI APIs...
# 4
hi miguel,over ride it like this.public Dimension getPreferredSize() { return getMinimumSize();}public Dimension getMinimumSize() { return new Dimension(250, 200);}-Harshaharshapr@comatindia.com
harsha_pr at 2007-6-29 3:09:46 > top of Java-index,Desktop,Core GUI APIs...
# 5

guys,

thank u for your feedback. After hours of tedious debugging, my applet is working fine in IE5. I found several 'hidden' bugs that were accepted by netscape6 but made IE5 crash:

canvas.setSize(getSize().width,myHeight);

I was only concerned with resizing the height. IE5 didn't like that line! (I used 0 instead, result is OK).

- I changed scrollpane.addImpl() to scrollpane.add(). I'm not sure this accomplish anything.

- I overrode getPreferredSize() like Harsha explained (not sure it made any difference).

- I erased my validate() statements.

Sorry, I don't really know more then that!

miguel

mjuteau2001 at 2007-6-29 3:09:46 > top of Java-index,Desktop,Core GUI APIs...
# 6

Hi miguel.

So you are doing ok. Good.

I'll clarify what I mean by overriding getPreferredSize().

(In response to the mail you sent me.)

Think of it as a substitution for setSize().

When you call setSize, you pass the width and hight values you want:

//setSize(width, height);

if you let the system set the size of the canvas (never calling setSize()) the size is set based upon the preferred size of the component. And the size is set everytime the component is layed out.

therfore:

public void getPreferredSize()

{

return new Dimension(width, height); //width and hight of the size you want.

}

When the size is to change you change the values of width and height member variables.

Then (to make the system lay out the canvas again, and setting the size again) you call

theCanvas.invalidate();

theScrollPane.validate();

";-)

Ragnvald Barth

Software engineer

Ragnvald at 2007-6-29 3:09:46 > top of Java-index,Desktop,Core GUI APIs...