Adjusting height of GWT Panels based on content

前端 未结 1 590
情话喂你
情话喂你 2021-01-15 04:08

We have many screens where different types of GWT panels are used.

One common problem across many screens is that, content size is derived at runtime. So, if I defi

相关标签:
1条回答
  • 2021-01-15 04:38

    In GWT (and HTML) you can either set the height of a panel or let it expand naturally. In general, once you set the height of something, you lose the ability to let it expand naturally.

    Some Panels in GWT implicitly set their own height (or require that you set their height) and so are never good choices for dynamically sized content. LayoutPanels and ScrollPanels, for example, can never adjust dynamically, and expect you to provide size information programmatically. FlowPanels and HTMLPanels, on the other hand, are great for dynamic heights and would rather you not set their height explicitly.

    If you want a scrolling panel, of course you have to define how high it should be - how else could it know when to scroll and when to just get bigger? But, you can put a FlowPanel (which expands automatically) inside a ScrollPanel (which you have set at 800px or whatever). Then, as you add content to the FlowPanel, it will expand inside the ScrollPanel. Users can then scroll to see different parts of the FlowPanel.

    Trouble-shooting tips:

    1. Make sure you aren't setting the height on panels that you want to expand naturally
    2. Make sure you ARE setting the height on panels that should always be the same size
    3. Try using FlowPanels instead of Horizontal/VerticalPanels
    4. *LayoutPanels and AbsolutePanels always need explicit sizes and can never grow dynamically as you add more content. Anything you want to grow with content should probably be a FlowPanel or HTMLPanel.
    0 讨论(0)
提交回复
热议问题