ComboBox

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.

Figure 2.13. The hierarchy of the ComboBox class


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.

Table 2.9. The attribute defined in the BaseValueComponent class
NameUsageTypeDefaultAccessibility
valueTag and JSanynullread-write
 Description. The value represented by this item.

Table 2.10. The attributes defined in the BaseFormItem class
NameUsageTypeDefaultAccessibility
submitTag and JSbooleantrueread-write
 Description. Indicates whether or not the value of this element will be submitted with the containing form.
submitnameTag and JSstring read-write
 Description. The parameter name used for this value when the containing form is submitted.

Table 2.11. The attributes defined in the BaseComboBox class
NameUsageTypeDefaultAccessibility
attachoffsetTag and JSnumber-1read-write
 Description. The vertical offset, in pixels, of the floating list attached to this combo box.
autoscrollbarTag and JSbooleantrueread-write
 Description. Indicates whether or not a scroll bar should be displayed when there are more items than the value of the shownitems attribute.
bordersizeTag and JSnumber1read-write
 Description. The border size of the popup list in pixels.
dataoptionTag and JSstringnoneread-write
 Description. One of “lazy”, “resize”, “pooling”, and “none”.
defaultselectionTag and JSnumber read-write
 Description. The number of the item initially selected.
editableTag and JSbooleantrueread-write
 Description. Indicates whether or not the items in this combo box are editable.
isopenTag and JSbooleanfalseread-write
 Description. Indicates whether or not the popup list is showing.
itemclassnameTag and JSstring read-write
 Description. The name of the class to instantiate when itemdatapath is assigned.
ondefaultselectionTag and JSexpression read-write
 Description. Invoked when the default selection is set.
shownitemsTag and JSnumber-1read-write
 Description. The number of items shown at a time.
spacingTag and JSnumber0read-write
 Description. The spacing between items in the popup list in pixels.
text_widthTag and JSnumber read-write
 Description. The text width. By default it is the width of this combo box – 19.
text_xTag and JSnumber2read-write
 Description. The x position of the text.
text_yTag and JSnumber2read-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.

Listing 2.10. Using a combo box (comboboxTest1.lzx)
<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.

Figure 2.14. Combo box


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.

Listing 2.11. Using the value attribute of textlistitem
<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>

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset