目前,我正在使用AbsoluteLayout,但是由于某些问题,我想尝试一下CssLayout。
我想动态地将图像,标签和按钮组件放置在布局中的特定位置。
AbsoluteLayout允许我这样指定位置:
absoluteLayout.addComponent(component, "top:20px;left:20px")
使用CssLayout完全可以实现这样的功能吗?
您可以通过getCss
在CssLayout上进行重写来为组件应用内联CSS ,因此以下内容应具有所需的结果:
CssLayout cssLayout = new CssLayout() {
@Override
protected String getCss(Component component) {
// check the component here and return correct css. In this case only one component in the layout so this works..
return "position: relative; top: 10px; left: 10px";
}
};
cssLayout.setSizeFull();
cssLayout.addComponent(new Button("Hello"));
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句