Layout in HorizontalPanel

2 views
Skip to first unread message

Xiris

unread,
Oct 11, 2006, 11:53:58 AM10/11/06
to Google Web Toolkit
Greetings All,

I am having some issues with layouts in a horiztonalPanel which is part
of a custom widget (based on composite) called HTMLButton.

The panel contains two widgets an Image and HTML (as a caption). When
I set the width of the HTMLButton widget I want the cell the image is
in to stay the same size and the HTML portion to expand into the
additional space.

If I don't specify the size of the image cell explicitly then it
expands to fill the space and the HTML part does not. Since this is a
re-usable widget I intially used the following:

int width = myImage.getOffsetWidth();
myPanel.setCellWidth(myImage, width+"px");

This caused a Javascript exception. From what I could trace this is
because getOffsetWidth always returns 0.

At present the only way I can get it to function as I want is to
explicitly set the cell width to the size of the image (in this case
48px). Which isn't much use if I want to use the same widget with
different sized images since there doesn't appear to be a way to get
the size of the image programmatically.

I am trying to achieve this during the widgets constructor. I have
tried it both before and after adding the image to the panel but with
the same result.

Does anyone have any ideas where I am going wrong or is it a bug?

thanks,
Jon

Mat Gessel

unread,
Oct 11, 2006, 4:15:28 PM10/11/06
to Google-We...@googlegroups.com
Hi Jon,

I ran into the same problem a while back. The image size is not known
until it is loaded and displayed. Some ideas:

a) set the size of the image's cell from a LoadListener. The image
size will be available then via getOffsetWidth/Height. A side-effect
is the re-layout will be noticeable on some platforms (Safari, Hosted
Browser).

b) create a subclass of image which requires width and height to be
specified. The panel can use this for layout before being shown.

c) add a stylename to the table cell and do layout with CSS.
HorizontalPanel does not expose TDs, so you will have to subclass it
or apply the stylename to a nested DIV.

-= Mat

--
Mat Gessel
http://www.asquare.net

Xiris

unread,
Oct 12, 2006, 4:30:48 AM10/12/06
to Google Web Toolkit
Thanks Mat,

I'd like it to be as automatic as possible without additional work so
the load listener sounds like the best option at present, shame about
the obvious repainting but I can live with that.

If I get a chance I'll take a closer look at the source for the Image
class and see if there is anything in there that could be done.
Thanks,
Jon

Xiris

unread,
Oct 12, 2006, 5:04:59 AM10/12/06
to Google Web Toolkit
Ok,

I have now added a loadlistener to the image and it seems to work fine
most of the time. However, it seems that the onLoad method isn't always
call?! In fact, with four images on screen on average only two of them
result in the onload method actually being called but it varies between
1 and 3.

I am currently using the hosted browser. Any possible reason this may
be happening?

thanks,
Jon

Reply all
Reply to author
Forward
0 new messages