Allowing Additions to the Combo List
Up
until now, the examples have
contained only a READ_ONLY
-style combo. In that mode, the text field
portion of the combo cannot be directly edited by the user. The user
must select an item from the list, at which time that item will be
displayed in read-only mode in the text field. However, the combo can
also be configured to enable the user to enter text in the text
portion that is not represented by a corresponding item on the list.
How do I do that?
To permit the user to enter text in the text
portion of the combo that does not directly correspond to an item in
the list portion, just use the
SWT.DROP_DOWN
style when you create the combo:
final Combo c1 = new Combo(s, SWT.DROP_DOWN);
As seen in Figure 8-5, drop-down-style combos have a slightly different look on the Windows platform. When the text portion has focus, you see a different mouse cursor, usually an I-beam, which indicates that the text field is editable.
Figure 8-5. The DROP_DOWN style
Note
Remember, since SWT will run in native code, the look and feel of the Combo will be different across platforms.
Since the combo now has a completely functional text field, the user can enter any text in the combo and is not limited to simply choosing an item on the list. This also opens up your code for the use of some text-field-specific methods, many of which will be familiar from the Chapter 5
Get SWT: A Developer's Notebook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.