Java 在 GWT 中创建流体面板来填充页面?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/86901/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Creating a fluid panel in GWT to fill the page?
提问by JP Richardson
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:
我想要一个 GWT 面板来填充页面,而不必实际设置大小。有没有办法做到这一点?目前我有以下几点:
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
08 年 9 月 17 日 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.
我在每一侧放了一些按钮(明确设置它们的大小),但仍然不起作用。我真的很惊讶没有像 FillLayout 类或 setFillLayout 方法或 setDockStyle(DockStyle.Fill) 或类似的东西。也许这是不可能的?但是像 GWT 一样受欢迎,我认为这是可能的。
UPDATE Sep 18 '08 at 14:38
08 年 9 月 18 日 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??
我尝试将 RootPanel 的宽度和高度设置为 100%,但仍然无效。感谢您的建议,这似乎可能会奏效。还有其他建议吗??
采纳答案by Ben Bederson
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
Google 已在其常见问题解答之一中回答了您问题的主要部分: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:
主要的一点是你不能将高度设置为 100%,你必须这样做:
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);
回答by Mike Monette
I think you'll need to put something on the left and/or right of the split (split.setLeftWidget(widget), split.setRightWidget(widget) OR split.add(widget), which will add first to the left, then to the right) in order for anything to show up.
我认为您需要在拆分的左侧和/或右侧放一些东西(split.setLeftWidget(widget), split.setRightWidget(widget) OR split.add(widget),这将首先添加到左侧,然后到右侧)以便显示任何内容。
回答by Mike Monette
Try setting the width and/or height of the rootpanel to 100% before adding your widget.
在添加小部件之前,尝试将根面板的宽度和/或高度设置为 100%。
回答by Drejc
Panels automatically resize to the smallest visible width. So you must resize every panel you add to the RootPanel to 100% including your SplitPanel. The RootPanel itself does not need resizing. So try:
面板会自动调整到最小的可见宽度。因此,您必须将添加到 RootPanel 的每个面板的大小调整为 100%,包括您的 SplitPanel。RootPanel 本身不需要调整大小。所以尝试:
split.setWidth("100%");
split.setHeight("100%");
回答by jgindin
The documentation for DecoratorPanelsays:
DecoratorPanel的文档说:
If you set the width or height of the DecoratorPanel, you need to set the height and width of the middleCenter cell to 100% so that the middleCenter cell takes up all of the available space. If you do not set the width and height of the DecoratorPanel, it will wrap its contents tightly.
如果设置DecoratorPanel的宽度或高度,则需要将middleCenter单元格的高度和宽度设置为100%,以便middleCenter单元格占用所有可用空间。如果不设置 DecoratorPanel 的宽度和高度,它将紧紧包裹其内容。
回答by jgindin
The problem is that DecoratorPanel middleCenter cell will fill tight on your contents as default, and SplitPanel doesn't allow "100%" style size setting. To do what you want, set the table's style appropriately, on your CSS:
问题是 DecoratorPanel middleCenter 单元格会默认填充您的内容,而 SplitPanel 不允许“100%”样式大小设置。要执行您想要的操作,请在您的 CSS 上适当地设置表格的样式:
.gwt-DecoratorPanel .middleCenter { height: 100%; width: 100%; }
.gwt-DecoratorPanel .middleCenter { 高度:100%;宽度:100%;}
回答by Brad
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 DockLayoutPanelto have your content fill the page vertically. See the sample mail app, which uses this panel.
Ben 的回答非常好,但也已过时。在 GWT 1.6 中需要调整大小处理程序,但我们现在是 2.4。您可以使用DockLayoutPanel让您的内容垂直填充页面。请参阅使用此面板的示例邮件应用程序。
回答by Rafael Capretz
For me it does not work if I just set the width like
对我来说,如果我只是将宽度设置为
panel.setWidth("100%");
panel.setWidth("100%");
The panel is a VerticalPanel that it just got a randomly size that I don't know where it comes from. But what @Ben Bederson commented worked very well for me after I added the line:
该面板是一个 VerticalPanel,它只是随机大小,我不知道它来自哪里。但是@Ben Bederson 在我添加了以下内容后评论的内容对我来说非常有效:
panel.setWidth(Window.getClientWidth() + "px");
panel.setWidth(Window.getClientWidth() + "px");
Just this, nothing else. Thanks
仅此而已,没有别的。谢谢