根据内容调整GWT面板的高度 [英] Adjusting height of GWT Panels based on content

查看:96
本文介绍了根据内容调整GWT面板的高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有很多屏幕使用不同类型的GWT面板。

跨越多个屏幕的一个常见问题是,内容大小是在运行时导出的。因此,如果我为面板定义高度(垂直/水平/ DockPanel),并且在面板内添加任何新组件或者内容更多时,面板高度保持不变。所以我们无法看到内容。 UI外观和感觉变得最差。

我们如何处理高度问题?当屏幕上的内容发生变化时,我们是否必须手动编写代码来调整每个面板/控件高度?这不是一种非常糟糕的编码方式吗?
另外,现在我们在一些地方有datagrids,如果没有记录的数量很少,我们会在datagrid下面看到一个巨大的空间,不知道我们该如何处理这些情况?

根据下面的注释更新了几个例子:
您的意思是说,无论何时我们知道内容垂直增长,我们都可以选择FlowPanel。因为,我们已经使用了垂直面板/水平面板的一些屏幕,并且在用户点击某些东西时会添加并显示新的字段。所以垂直面板/水平面板高度自动不调整。再举一个例子,我们在码头布局面板内容区域内有主要的垂直面板,并且里面有一些其内容可能不同的小部件。所以现在如果我使用FlowPanel来处理大小不一的内容,那么外板呢?将得到它调整?再次说我们使用过的那种面板 - 码头布局面板与固定的页眉,页脚,左侧菜单和内容区域一起使用。内容区域内使用滚动面板。我们所有不同的小部件都在这里,这是混合和水平/垂直/ datagrids..etc匹配。

解决方案

在GWT(和HTML)中,您可以设置面板的高度或让其自然展开。一般来说,一旦你设置了某物的高度,你就失去了让它自然展开的能力。



GWT中的一些面板隐式设置了自己的高度(或者要求你设置它们的高度),因此对于动态大小的内容而言,永远不会是好选择例如,LayoutPanels和ScrollPanels不能动态调整,并希望以编程方式提供大小信息。另一方面,FlowPanels和HTMLPanel对于动态高度来说非常适合,而不是明确地设置高度。



如果你想要一个滚动面板,当然你有以确定它应该有多高 - 还有什么可以知道何时滚动以及何时变得更大?但是,你可以在一个ScrollPanel(你已经设置为800px或其他)中放置一个FlowPanel(可以自动扩展)。然后,在将内容添加到FlowPanel时,它将在ScrollPanel内部展开。用户可以滚动查看FlowPanel的不同部分。



故障排除提示:


  1. 确保您未在​​要自然展开的面板上设置高度

  2. 确保您在面板上设置的高度始终应该相同
  3. li>
  4. 尝试使用FlowPanel而不是水平/垂直面板

  5. * LayoutPanels和AbsolutePanels始终需要显式大小,并且不会随着添加更多内容而动态增长。任何你想随内容增长的东西都应该是一个FlowPanel或HTMLPanel。


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 define a height for a panel(Vertical/Horizontal/DockPanel) and when any new components are getting added within panel or content is more, panel height remains the same. So we are not able to see the contents. UI look and feel becomes worst.

How do we handle the height problems? Do we have to manually code to adjust every panel/widget height when something gets changed in screen. Is it not a very bad way of coding? Also, now we have datagrids at some places, if no of records are very less, we see a huge space left out below datagrid, not sure how do we handle these cases?

Updated below with few examples as per the comment: Do you mean to say that whenever we know that content grows vertically, we can always choose FlowPanel. Because, some of the screens we have used Vertical panel/Horizontal Panel and inside that when user clicks something a new fields getting added and shown. So Vertical Panel/Horizontal Panel height automatically not getting adjusted. One more example is that we have main Vertical Panel within a Dock Layout Panel content area and inside that there are some widgets whose content may vary. So now if I use a FlowPanel to the content which varies in size, what about outer panels? Will get it adjusted? Again to say the kind of panels we have used - Dock Layout Panel is used with fixed header, footer, left menu and Content area. A scroll panel is used within Content area. All our different widgets go inside this which is mix and match of horizontal/vertical/datagrids..etc.

解决方案

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.

这篇关于根据内容调整GWT面板的高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆