Using the SIMPLE Style

The final style for Combo objects is the seldom-used SWT.SIMPLE style. The SIMPLE style is used to create a combo in which the list portion of the combo is always visible.

How do I do that?

SIMPLE Combo objects are created simply by changing the style passed in at the time the Combo object is created:

final Combo c = new Combo(s, SWT.SIMPLE);
c.setBounds(50, 50, 150, 65);
String items[] = {"Item One", "Item Two", "Item Three", "Item Four", "Item Five"};

This code causes Figure 8-6 to be displayed. As you can see, the list portion of the combo appears in its dropped-down state. Of course, this negates much of the space savings that serve as the primary reason for use of Combo over List. It is appropriate, however, when you want to enable the user to add items not in the list while having the advantage of an always-visible list.

A SIMPLE-style combo

Figure 8-6. A SIMPLE-style combo

In all respects, a SIMPLE -style combo will work like a DROP_DOWN -style combo, including the ability to edit the text portion.

This chapter completes our look at the four main SWT widget types—Text, Button, List, and Combo. These four widgets comprise the major user-interface elements that are used to construct graphical applications. But there is more to designing a user interface than knowing which widget to use and how to use them. You also need to consider matters related to complex designs of widget locations ...

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.