鍍金池/ 教程/ Java/ UI 組件-自定義組件
UI 組件-自定義組件
UI 布局-Panel
UI 組件-Slider 組件
UI 組件-Button
UI 組件-PasswordField
UI 布局-TabSheet 布局
Vaadin Web 應(yīng)用的基本組成部分
UI 組件-Label
UI 組件-Link
UI 布局-GridLayout 布局
安裝開發(fā)環(huán)境
UI 組件-Tree 組件
UI組件-Select 組件
UI 布局-概述
UI 組件-RichTextArea
UI 組件-Table 組件
使用 Item 介面管理一組 Property
使用資源
UI 組件-TextArea
SQLContainer-編輯
SQLContainer-過濾及排序
UI 組件-TextField
UI 布局-HorizontalSplitPanel 和 VerticalSplitPanel 布局
SQLContainer-引用其它 SQLContainer
UI組件-ProgressIndicator組件
開始編寫 Web 應(yīng)用
UI組件-Form組件
UI 布局-Accordion 布局
SQLContainer-使用 FreeformQuery
SQLContainer 概述
使用主題-創(chuàng)建和應(yīng)用新主題
概述
UI 布局-AbsoluteLayout 布局
UI 組件-Upload 組件
使用主題-概述
UI 布局-FormLayout 布局
MenuBar 組件
UI 布局-VerticalLayout 和 HorizontalLayout 布局
UI 組件-Embedded 組件
UI 組件概述
使用 Container 介面管理一組 Item
UI 組件-LoginForm 組件
數(shù)據(jù)綁定-Property 接口
Vaadin 應(yīng)用程序框架介紹
開始使用 SQLContainer
UI 組件-Checkbox
可視化界面編輯插件
數(shù)據(jù)綁定-概述

UI 組件-自定義組件

Vaadin 支持自定義組件,典型的用法是將各種 Vaadin 內(nèi)置的組件組合而成構(gòu)成自定義組件。 創(chuàng)建自定義組件可以通過派生 CustomComponent 然后調(diào)用 setCompositionRoot 為自定義組件設(shè)置根容器。 例如:

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);
    }}

http://wiki.jikexueyuan.com/project/vaadin-web-development-tutorial/images/70.png" alt="" />

需要注意的是,如果希望自定義的組件自適應(yīng)其所包含的其它UI組件,必須將容器的大小設(shè)為“未定義”,如上面的 setSizeUndefined 方法就是起這個(gè)作用。 構(gòu)造自定義組件,也可以從其它 Vaadin 內(nèi)置 UI 組件派生,或者利用 Google Web Toolbit 提供的組件創(chuàng)建全新的 Vaadin UI 組件(后面介紹)。

Tags: Java EE, Vaadin, Web