Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
book-of-vaadin.pdf
Скачиваний:
88
Добавлен:
24.03.2015
Размер:
13.43 Mб
Скачать

User Interface Components

Figure 5.2. Component Interfaces and Abstractions

5.2.1. Component Interface

The Component interface is paired with the AbstractComponent class, which implements all the methods defined in the interface.

Component Tree Management

Components are laid out in the user interface hierarchically. The layout is managed by layout components, or more generally components that implement the ComponentContainer interface. Such a container is the parent of the contained components.

The getParent() method allows retrieving the parent component of a component. While there is a setParent(), you rarely need it as you usually add components with the addComponent() method of the ComponentContainer interface, which automatically sets the parent.

A component does not know its parent when the component is still being created, so you can not refer to the parent in the constructor with getParent().

Attaching a component to an UI triggers a call to its attach() method. Correspondingly, removing a component from a container triggers calling the detach() method. If the parent of an added component is already connected to the UI, the attach() is called immediately from setParent().

public class AttachExample extends CustomComponent { public AttachExample() {

}

@Override

public void attach() { super.attach(); // Must call.

// Now we know who ultimately owns us. ClassResource r = new ClassResource("smiley.jpg");

92

Component Interface

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]