在Panel上截断GWT小部件

时间:2013-03-28 08:57:57

标签: image gwt

我有以下课程,它将图像添加到按钮,然后将按钮添加到面板

private PushButton button;
private AbsolutePanel panel = new AbsolutePanel();
private Image image = new Image("images/rectangle_blue.png");

public ExpandingRectangularButton(String text)
{
    String width = "120px";
    String height = "160px";
    image.setWidth(width);
    image.setHeight(height);
    button = new PushButton(image);
    panel.add(button, 0, 0);
    panel.setWidth(width);
    panel.setHeight(height);
    initWidget( panel );
}

当我显示ExpandingRectangularButton的实例时,按钮在底部被截断。但是,如果我将面板排除在以下等式之外

private PushButton button;
private Image image = new Image("images/rectangle_blue.png");

public ExpandingRectangularButton(String text)
{
    String width = "120px";
    String height = "160px";
    image.setWidth(width);
    image.setHeight(height);
    button = new PushButton(image);
    initWidget( button );
}

只需使用图像和按钮(即我在按钮上调用init()),然后图像将显示没有截断。由于我没有设置按钮的高度,我认为它会动态增长以容纳它的子窗口小部件。当我将按钮放在面板上时,为什么不会发生这种情况?

1 个答案:

答案 0 :(得分:0)

引用Javadoc:

  

一个绝对的小组绝对会让所有孩子都站起来,让他们重叠。

     

请注意,此面板不会自动调整大小,以便为其绝对定位的孩子留出足够的空间。必须明确调整大小以便为它们腾出空间。

你可以:

  • 明确设置AbsolutePanel尺寸;
  • 从中移除overflow: hidden属性(解决方法);
  • 使用panel.add(button, -1, -1)静态定位按钮;
  • AbsolutePanel更改为自然适应其大小的Panel(与几乎所有其他{{1}}一样)。

我更喜欢最后一个,但你的用例并不清楚。

相关问题