0

I have, maybe, a stupid question, take my apologies, but I have used GWT just 1 month.

I would like to use height of panel which use another panel but I got 0 value :

FlowPanel first = new FlowPanel();
Label flexLabel = new Label("some content");
Button button = new Button();

first.add(flexLabel);
first.add(button);


FlowPanel second = new FlowPanel();
second.setHeight(first.getElement().getClientHeight()); // set 0 value always

Why I always got 0 ?? I understand that GWT engine sets this value at runtime when it translates java code to javascript, but why it does not set appropriate value ? How can I work around this?

idmitriev
  • 4,619
  • 4
  • 28
  • 44
  • When is this code getting called? Remeber that client height will be available only after the ui is rendered. There are alternative ways to layout your UI instead of using this technique. – 6ton Aug 04 '14 at 16:18
  • second.setHeight(first.getElement().getClientHeight()); - this called. I see height available only after ui is rendered. What is "to layout" ?? Problem that I have to have the same heigth of first panel for second panel. Second panel depends on first. – idmitriev Aug 04 '14 at 16:20
  • Do you add the the `FlowPanel first` to the root container? – Markus Aug 04 '14 at 16:26
  • yeap. RootPanel.get().add(first) – idmitriev Aug 04 '14 at 21:35

1 Answers1

2

All widgets, including panels, in GWT have a size of zero until the browser finishes rendering them.

You have two options.

  1. Render your layout. Then ask for a height of the first panel inside a deferred Scheduler command (read more here: GWT: Timer and Scheduler Classes). Use this height to adjust the second panel. Fortunately, in a production mode it all happens very quickly, so users are not likely to notice it.

  2. If you want to position these panels side by side, you can use a LayoutPanel or a HorizontalPanel to achieve the same effect.

Community
  • 1
  • 1
Andrei Volgin
  • 40,755
  • 6
  • 49
  • 58
  • Andrei hi, I have a question about Timer. I make timer which sets height to my panel and set timer.schedule(1); but sometimes I observed that height does not set. Can you explain what's wrong ? Thx in advance – idmitriev Aug 06 '14 at 16:20
  • What is the reason to use a Timer instead of a Scheduler for setting a height? – Andrei Volgin Aug 06 '14 at 17:03
  • In a Timer you set a specified time which may or may not be enough. I cannot tell without looking at your code and, possibly, profiling your app why a specified time delay is not enough in some cases. In a Scheduler you simply say "whenever you finish rendering the page, do this". – Andrei Volgin Aug 06 '14 at 18:55