GWT LayoutPanel大小 [英] GWT LayoutPanel size

查看:90
本文介绍了GWT LayoutPanel大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用GWT中的LayoutPanel尝试一些示例。我试图将一个布局面板(大小100%,100%)放置到一个ScrollPanel上,该ScrollPanel依次连接到rootlayoutPanel。尽管我已分配的高度为100%,但它并未显示要在rootlayout面板中填充的布局面板。即使我将一个小部件添加到布局面板,它在设计器视图中也是不可见的。我可以通过在设计器视图中显式拖动布局面板来查看它们。但是,这最终会迫使大小以像素为单位。为什么我找到这种行为?下面是代码:

I was trying some examples with LayoutPanel in GWT. I tried to place a layoutpanel (with size 100%,100%) onto a ScrollPanel that in turn is attached to the rootlayoutPanel. Though the height I have assigned is 100%, it is not showing the layoutpanel to be filled in the rootlayoutpanel. Even if I add a widget to the layoutpanel, its not visible in the designer's view. I could view them by dragging explicitly the layoutpanel on the designer view. But, this would ultimately force the size to be in pixels. why am I finding this behaviour? below is the code:

RootLayoutPanel rp = RootLayoutPanel.get();

LayoutPanel lp = new LayoutPanel();

lp.setSize("100%","100%");

ScrollPanel sp = new ScrollPanel(lp);

rp.add(lp);

使用这段代码,我可以看到layoutPanel仅作为一行。我看不到Layoutpanel覆盖的区域(框)。如果我尝试通过拖动手动更改高度,它会自动将layoutpanel的高度更改为像素:

with this code, I could see the layoutPanel only as a line. I couldn't see the area (box) covered by Layoutpanel. If I try to manually change the height by dragging, it automatically changes the height of the layoutpanel to pixels:

lp.setsize("100%","500px");

为什么我看到这种行为?有什么解释吗?

why am I seeing this behaviour? Is there any explanation??

推荐答案

布局面板可能会非常棘手。 LayoutPanels基本上是绝对的面板,用于完整页面的Web应用程序。为了使它从根面板向下(或调用调整大小并具有固定大小的面板)工作所有面板,必须具有 RequiresResize 。在你的情况下(除了你的例子中的错误,你添加lp而不是sp到rootpanel,但我假设你打算添加sp),你在RootPanel和LayoutPanel之间放置一个非LayoutPanel,这将打破布局流程,因此LayoutPanel lp不能自动调整大小。 LayoutPanel将不会获得高度/宽度。

Layout panels can be tricky. LayoutPanels are basically absolute panels, which are intended for full page web apps. To make it work all panels from the root panel down (or from the panel where resize is called and has a fixed size) must have RequiresResize. In your case (besides the err in your example where you add lp instead of sp to the rootpanel, but I assume you intended sp to be added), you put a non LayoutPanel between the RootPanel and the LayoutPanel, this breaks the layout flow and thus the LayoutPanel lp can't be automatically resized. The LayoutPanel will get no height/width.

然而,将ScrollPanel和LayoutPanels一起使用是不可行的。LayoutPanel的整个想法是推导它的大小基于它的父级大小,但在ScrollPanel中,大小没有关系,所以不能设置LayoutPanel的大小。

However, using a ScrollPanel together with LayoutPanels isn't going to work.The whole idea of a LayoutPanel is to derive it's size based on it's parent size, but inside a ScrollPanel the size isn't related, so the size of a LayoutPanel can't be set.

这篇关于GWT LayoutPanel大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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