2
votes

I'm unable to get the height of the widget in my code

docklayoutpanel.setHeight("1900px");
String height=Integer.toString(docklayoutpanel.getOffsetHeight());
String heightt=height+"px";
System.out.println(heightt);

but the o/p is always 0px.

2
Could you add code where docklayoutpanel's constructor call is? - qben
the is too long to be uploaded... :( - Piyush Srivastava
I'm thinking about widget(s) docklayoutpanel contains. Maybe there is the answer for your question. - qben
i have just taken a Scroll Panel on which i have added dockLayoutPanel whose center flow panel is having dynamic size and i have to set the height of center flow panel to docklayoutpanel and in this when i m trying to fetch the height of the flowpanel it is returning zero 0 only... - Piyush Srivastava
Maybe dockLayoutPanel's height is 0px beacause it doesn't contain any widgets. Does it have any? - qben

2 Answers

1
votes

The question is old but I had the same problem and it took me quite long to solve it. So to help others here is my solution. I'm using UIBinder to constuct my views and in the constructor I added a Scheduler.

public class MyWidgetImpl extends Composite implements MyWidget {

@UiTemplate("MyWidget.ui.xml")
interface MainViewUiBinder extends UiBinder<Widget, MyWidgetImpl> {
}

@UiField(provided = true)
InputPanel inputPanel;

@UiField(provided = true)
ResultPanel resultPanel;

public MyWidgetImpl() {
    inputPanel = ClientFactory.getInputPanel();
    resultPanel = ClientFactory.getResultPanel();

    MainViewUiBinder uiBinder = GWT.create(MainViewUiBinder.class);
    initWidget(uiBinder.createAndBindUi(this));

    Window.addResizeHandler(new ResizeHandler() {
        public void onResize(ResizeEvent event) {
            resize();
        }
    });


    Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
        public void execute() {
            resize();
        }
    });
}

private void resize() {
    if(Window.getClientHeight() > resultPanel.getCellTree().getAbsoluteTop())
        resultPanel.getScrollPanel().setHeight((Window.getClientHeight() - resultPanel.getCellTree().getAbsoluteTop()) + "px");
}

}

0
votes

It depends where do you call this code. Height will be available after load i.e. you can get you height in onLoad() method