Wednesday, March 28, 2012

Re: DockLayoutPanel.getOffsetHeight return zero even after calling forceLayout()

I have had this problem before.
The widget needs to be visible before it knows the size atributes.

Here is some code that might help you. you need to schedule a
deferred commad. Do some searched to understand object.

Hope this helps!

public static void adjustHeight(final DockLayoutPanel topPanel,
final SimplePanel bodyPanel, final DockLayoutPanel outerPanel, final
boolean isIpad)
{
Scheduler.get().scheduleDeferred(new
Scheduler.ScheduledCommand()
{
public void execute()
{
int width = Window.getClientWidth() - 7;
int height = Window.getClientHeight() - 7;
if(isIpad)
{
width = width - 40;
}

On Mar 28, 5:46 am, tong123123 <tong123...@gmail.com> wrote:
> the code is attached as follow:
>
> public class ALS implements EntryPoint {
>
>
>
>
>
> >    ScrollPanel basePanel = new ScrollPanel();
> >    DockLayoutPanel baseDockLayoutPanel = new DockLayoutPanel(Unit.PX);
> >    SimplePanel simpleContentPanel = new SimplePanel();
>
> >    public void onModuleLoad() {
> >            RootLayoutPanel rootPanel = RootLayoutPanel.get();
> >            rootPanel.add(basePanel);
> >            basePanel.add(baseDockLayoutPanel);
> >            baseDockLayoutPanel.setSize("1200", "800");
> >            baseDockLayoutPanel.addNorth(CommonPanel.getHeaderPanel(), 20);
> >            baseDockLayoutPanel.addSouth(CommonPanel.getFooterPanel(), 40);
> >            FlowPanel leftSidePanel = CommonPanel.getLeftSidePanel();
> >            FlowPanel menuPanel = new FlowPanel();
> >            menuPanel.setWidth("150px");
> >            menuPanel.addStyleName("menu");
> >            menuPanel.add(buildTree());
> >            leftSidePanel.add(menuPanel);
> >            baseDockLayoutPanel.addWest(leftSidePanel, 220);
> >            baseDockLayoutPanel.add(simpleContentPanel);
> >            baseDockLayoutPanel.setSize("1024", "800");
>
> >    }
>
> >    Tree buildTree(){
> >            Tree treeMenu = new Tree();
>
> >            final TreeItem searchLogs = new TreeItem("Search Logs");
> >            treeMenu.addItem(searchLogs);
> >            searchLogs.setState(true);
>
> >            treeMenu.addSelectionHandler(new SelectionHandler<TreeItem>(){
>
> >                    @Override
> >                    public void onSelection(SelectionEvent<TreeItem> event) {
> >                            if (event.getSelectedItem().equals(advancedSearchLogs)){
> >                                    //System.out.println(splitLayoutPanel.getWidgetCount());
> >                                    simpleContentPanel.remove(simpleContentPanel.getWidget());
> >                                    simpleContentPanel.add(new AdvancedSearchLogsPanel());
> >                                    advancedSearchLogsPanel.forceLayout();
> >                                    baseDockLayoutPanel.forceLayout();
>
> >                                    int width = advancedSearchLogsPanel.getOffsetWidth() + 220;
> >                                    int height = advancedSearchLogsPanel.getOffsetHeight()+ 60;
> >                                    // Problem here, getOffSetheight() return zero!!
> >                                    // AdvancedSearchLogsPanel is a docklayoutPanel
> >                                    baseDockLayoutPanel.setSize(String.valueOf(width), String.valueOf(height));
> >                            }
> >                    }});
> >            return treeMenu;
> >    }
> > }
>
> On Wednesday, March 28, 2012 4:08:00 PM UTC+8, tong123123 wrote:
>
> > there is a simplePanel and the simplePanel add a DockLayoutPanel called
> > AdvancedSearchPanel.
> > in the AdvancedSearchPanel constructor, the width is set to 100% and
> > height to 1800px.
>
> > then there is a menu item and when it is clicked,
> > I try to add the AdvancedSearchLogsPanel() to simplePanel and then called
> > advancedSearchLogsPanel.forceLayout()
> > before calling
> > advancedSearchLogsPanel.getOffsetWidth() and
> > advancedSearchLogsPanel.getOffsetHeight()
> > but both return zero!!
>
> > what is the problem come from?
>
> On Wednesday, March 28, 2012 4:08:00 PM UTC+8, tong123123 wrote:
>
> > there is a simplePanel and the simplePanel add a DockLayoutPanel called
> > AdvancedSearchPanel.
> > in the AdvancedSearchPanel constructor, the width is set to 100% and
> > height to 1800px.
>
> > then there is a menu item and when it is clicked,
> > I try to add the AdvancedSearchLogsPanel() to simplePanel and then called
> > advancedSearchLogsPanel.forceLayout()
> > before calling
> > advancedSearchLogsPanel.getOffsetWidth() and
> > advancedSearchLogsPanel.getOffsetHeight()
> > but both return zero!!
>
> > what is the problem come from?- Hide quoted text -
>
> - Show quoted text -

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

No comments:

Post a Comment