我有以下类,它将图像添加到按钮,然后将按钮添加到面板
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() )然后图像将显示而不会被截断。由于我没有设置按钮的高度,我假设它会动态增长以适应它的子小部件。为什么我将按钮放在面板上时不会发生这种情况?