Chapter 8. The SWT Combo
The last of the four basic SWT widget classes is the
Combo
.
Combo
s are used to gather information by enabling
the user to choose from a list of items or to
enter text not in the list. It combines the functionality of the
List
class with functionality from the
Text
class, hence the name
combo
. In other toolkits, you may find the combo
box referred to by an older name—the drop-down listbox.
Since the Combo
is a combination of two classes,
you must consider each aspect of the class separately. This chapter
begins with an examination of the List
aspects of
Combo
, and then continues with the
Text
aspects. You will find much of this material
familiar after having read the chapters that cover
Text
and List
.
Creating a Combo List
As
with all
widgets, you must add a Combo
to a
Shell
or other container by creating an instance
of the Combo
class and passing it the parameters
required to create the desired style effects.
How do I do that?
By this stage of the process of learning SWT programming, you should
be proficient in the code needed to add a widget to a shell and to
specify the
style
of the widget. For Combo
, there are three basic
styles—SWT.DROP_DOWN
,
SWT.READ_ONLY
, and SWT.SIMPLE
.
This code, which creates, sizes, and positions a
Combo
, should be familiar:
final Combo c = new Combo(s, SWT.READ_ONLY); c.setBounds(50, 50, 150, 65);
The preceding code creates a Combo
that has the
SWT.READ_ONLY
style. The
SWT.READ_ONLY
style is used to enable the user to select only ...
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.