首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

Vaadin Web应用开发课程(27):UI组件-自定义组件

2012-09-09 
Vaadin Web应用开发教程(27):UI组件-自定义组件Vaadin 支持自定义组件,典型的用法是将各种Vaadin内置的组

Vaadin Web应用开发教程(27):UI组件-自定义组件

Vaadin 支持自定义组件,典型的用法是将各种Vaadin内置的组件组合而成构成自定义组件。 创建自定义组件可以通过派生CustomComponent 然后调用setCompositionRoot 为自定义组件设置根容器。
例如:

class MyComposite extends CustomComponent {    public MyComposite(String message) {        // A layout structure used for composition        Panel panel = new Panel("My Custom Component");        panel.setContent(new VerticalLayout());                // Compose from multiple components        Label label = new Label(message);        label.setSizeUndefined(); // Shrink        panel.addComponent(label);        panel.addComponent(new Button("Ok"));        // Set the size as undefined at all levels        panel.getContent().setSizeUndefined();        panel.setSizeUndefined();        setSizeUndefined();        // The composition root MUST be set        setCompositionRoot(panel);    }}


Vaadin Web应用开发课程(27):UI组件-自定义组件
需要注意的是,如果希望自定义的组件自适应其所包含的其它UI组件,必须将容器的大小设为“未定义”,如上面的setSizeUndefined方法就是起这个作用。
构造自定义组件,也可以从其它Vaadin内置UI组件派生,或者利用Google Web Toolbit提供的组件创建全新的Vaadin UI组件(后面介绍)。

热点排行