Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a fluid panel in GWT to fill the page?

Tags:

java

gwt

I would like a panel in GWT to fill the page without actually having to set the size. Is there a way to do this? Currently I have the following:

public class Main  implements EntryPoint
{
    public void onModuleLoad()
    {
        HorizontalSplitPanel split = new HorizontalSplitPanel();
        //split.setSize("250px", "500px");
        split.setSplitPosition("30%");

        DecoratorPanel dp = new DecoratorPanel();
        dp.setWidget(split);

        RootPanel.get().add(dp);
    }

}

With the previous code snippet, nothing shows up. Is there a method call I am missing?

Thanks.


UPDATE Sep 17 '08 at 20:15

I put some buttons (explicitly set their size) on each side and that still doesn't work. I'm really surprised there isn't like a FillLayout class or a setFillLayout method or setDockStyle(DockStyle.Fill) or something like that. Maybe it's not possible? But for as popular as GWT is, I would think it would be possible.

UPDATE Sep 18 '08 at 14:38

I have tried setting the RootPanel width and height to 100% and that still didn't work. Thanks for the suggestion though, that seemed like it maybe was going to work. Any other suggestions??

like image 392
JP Richardson Avatar asked Sep 17 '08 19:09

JP Richardson


2 Answers

Google has answered the main part of your question in one of their FAQs: http://code.google.com/webtoolkit/doc/1.6/FAQ_UI.html#How_do_I_create_an_app_that_fills_the_page_vertically_when_the_b

The primary point is that you can't set height to 100%, you must do something like this:

final VerticalPanel vp = new VerticalPanel();
vp.add(mainPanel);
vp.setWidth("100%");
vp.setHeight(Window.getClientHeight() + "px");
Window.addResizeHandler(new ResizeHandler() {

  public void onResize(ResizeEvent event) {
    int height = event.getHeight();
    vp.setHeight(height + "px");
  }
});
RootPanel.get().add(vp);
like image 175
Ben Bederson Avatar answered Nov 14 '22 14:11

Ben Bederson


Ben's answer is very good, but is also out of date. A resize handler was necessary in GWT 1.6, but we are at 2.4 now. You can use a DockLayoutPanel to have your content fill the page vertically. See the sample mail app, which uses this panel.

like image 37
Brad Avatar answered Nov 14 '22 16:11

Brad