The ComboBox class represents a combo box. This class is a direct subclass of BaseComboBox, which extends BaseFormItem. BaseFormItem is derived from the BaseValueComponent class, which itself is a direct subclass of BaseComponent. The class hierarchy is shown in Figure 2.13.
Tables 2.9, 2.10, and 2.11 list the attributes defined in the BaseValueComponent class, the BaseFormItem class, and the BaseComboBox class, respectively. The ComboBox class does not add new attributes.
Name | Usage | Type | Default | Accessibility |
---|---|---|---|---|
value | Tag and JS | any | null | read-write |
Description. The value represented by this item. |
Name | Usage | Type | Default | Accessibility |
---|---|---|---|---|
submit | Tag and JS | boolean | true | read-write |
Description. Indicates whether or not the value of this element will be submitted with the containing form. | ||||
submitname | Tag and JS | string | read-write | |
Description. The parameter name used for this value when the containing form is submitted. |
Name | Usage | Type | Default | Accessibility |
---|---|---|---|---|
attachoffset | Tag and JS | number | -1 | read-write |
Description. The vertical offset, in pixels, of the floating list attached to this combo box. | ||||
autoscrollbar | Tag and JS | boolean | true | read-write |
Description. Indicates whether or not a scroll bar should be displayed when there are more items than the value of the shownitems attribute. | ||||
bordersize | Tag and JS | number | 1 | read-write |
Description. The border size of the popup list in pixels. | ||||
dataoption | Tag and JS | string | none | read-write |
Description. One of “lazy”, “resize”, “pooling”, and “none”. | ||||
defaultselection | Tag and JS | number | read-write | |
Description. The number of the item initially selected. | ||||
editable | Tag and JS | boolean | true | read-write |
Description. Indicates whether or not the items in this combo box are editable. | ||||
isopen | Tag and JS | boolean | false | read-write |
Description. Indicates whether or not the popup list is showing. | ||||
itemclassname | Tag and JS | string | read-write | |
Description. The name of the class to instantiate when itemdatapath is assigned. | ||||
ondefaultselection | Tag and JS | expression | read-write | |
Description. Invoked when the default selection is set. | ||||
shownitems | Tag and JS | number | -1 | read-write |
Description. The number of items shown at a time. | ||||
spacing | Tag and JS | number | 0 | read-write |
Description. The spacing between items in the popup list in pixels. | ||||
text_width | Tag and JS | number | read-write | |
Description. The text width. By default it is the width of this combo box – 19. | ||||
text_x | Tag and JS | number | 2 | read-write |
Description. The x position of the text. | ||||
text_y | Tag and JS | number | 2 | read-write |
Description. The y position of the text. |
The BaseValueComponent class adds one method, getValue. Its signature is as follows:
getValue()
Returns the value contained by the BaseValueComponent object.
The BaseFormItem class does not add new methods.
The BaseComboBox class adds the following methods:
addItem(text, value)
Adds the specified text/value pair. The text argument is of type string and the value argument is of type Object.
clearSelection()
Clear the selection list.
getItem(value)
Return the specified value as Object; returns null if the combo box does not contain the specified value.
getItemAt(index)
Returns the item at the specified index.
getSelection()
Returns the current selection.
getText()
Returns the displayed text.
getValue()
Returns the value for the combo box.
removeItem(value)
Removes the specified item.
removeItemAt(index)
Removes the item at the specified index.
select(item)
Selects the specified item.
selectItem(value)
Selects an item by value.
selectItemAt(index)
Selects the item at the specified index.
setDefaultSelection(position)
Sets the item in the specified position.
setItemclassname(name)
Specifies the name of the class to instantiate in the floating list when necessary.
setOpen(open, withKey)
Sets the open/cloase state of the popup list. Both the open and withKey arguments are boolean.
setText(text)
Sets the displayed text.
toggle(withKey)
Toggles the open/close state of the popup list.
The ComboBox class does not add new methods.
As an example, the code in Listing 2.10 shows an LZX application that uses the combobox tag to create a ComboBox object.
<canvas width="150" height="150"> <combobox id="genre" x="5" y="3" width="100" editable="false"> <textlistitem text="Jazz"/> <textlistitem text="Pop"/> <textlistitem text="Blues"/> </combobox> </canvas> |
To invoke the LZX application, use this URL:
http://localhost:8080/lps-4.0.x/app02/comboboxTest1.lzx
The generated output is shown in Figure 2.14.
You can also use the value attribute in a textlistitem element if the value of an item is different than the display text, as demonstrated in Listing 2.11.
<canvas width="150" height="150"> <combobox id="genre" x="5" y="3" width="100" editable="false"> <textlistitem text="Jazz" value="1"/> <textlistitem text="Pop" value="2"/> <textlistitem text="Blues" value="3"/> </combobox> </canvas> |