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

User Interface Components

The setColumns() allows setting the width of the list as "columns", which is a measure that depends on the browser.

Figure 5.40. The NativeSelect Component

Multiple selection mode is not allowed; you should use the ListSelect component instead. Also adding new items, which would be enabled with setNewItemsAllowed(), is not allowed.

CSS Style Rules

.v-select {}

.v-select-select {}

The component has a v-select overall style. The native select element has v-select-select style.

5.14.5. Radio Button and Check Box Groups with OptionGroup

The OptionGroup class provides selection from alternatives using a group of radio buttons in single selection mode. In multiple selection mode, the items show up as check boxes.

OptionGroup optiongroup = new OptionGroup("My Option Group");

// Use the multiple selection mode. myselect.setMultiSelect(true);

Figure 5.41, “Option Button Group in Single and Multiple Selection Mode” shows the OptionGroup in both single and multiple selection mode.

Figure 5.41. Option Button Group in Single and Multiple Selection Mode

134

Radio Button and Check Box Groups with OptionGroup

User Interface Components

You can create check boxes individually using the CheckBox class, as described in Section 5.13, “CheckBox”. The advantages of the OptionGroup component are that as it maintains the individual check box objects, you can get an array of the currently selected items easily, and that you can easily change the appearance of a single component.

Disabling Items

You can disable individual items in an OptionGroup with setItemEnabled(). The user can not select or deselect disabled items in multi-select mode, but in single-select mode the use can change the selection from a disabled to an enabled item. The selections can be changed programmatically regardless of whether an item is enabled or disabled. You can find out whether an item is enabled with isItemEnabled().

The setItemEnabled() identifies the item to be disabled by its item ID.

// Have an option group

OptionGroup group = new OptionGroup("My Disabled Group"); group.addItem("One");

group.addItem("Two");

group.addItem("Three");

// Disable one item group.setItemEnabled("Two", false);

The item IDs are also used for the captions in this example. The result is shown in Figure 5.42, “OptionGroup with a Disabled Item”.

Figure 5.42. OptionGroup with a Disabled Item

Setting an item as disabled turns on the v-disabled style for it.

CSS Style Rules

.v-select-optiongroup {}

.v-select-option.v-checkbox {}

.v-select-option.v-radiobutton {}

The v-select-optiongroup is the overall style for the component. Each check box will have the v-checkbox style, borrowed from the CheckBox component, and each radio button the v-radiobutton style. Both the radio buttons and check boxes will also have the v-select-option style that allows styling regardless of the option type. Disabled items have additionally the v-disabled style.

The options are normally laid out vertically. You can use horizontal layout by setting display: inline-block for the options. The nowrap setting for the overall element prevents wrapping if there is not enough horizontal space in the layout, or if the horizontal width is undefined.

/* Lay the options horizontally */

.v-select-optiongroup-horizontal .v-select-option { display: inline-block;

}

/* Avoid wrapping if the layout is too tight */

.v-select-optiongroup-horizontal {

Radio Button and Check Box Groups with OptionGroup

135

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