Adding Items to a Combo List

In keeping with the List nature of a Combo, the next step you must take when creating a Combo is to add items to the list.

How do I do that?

As with List objects, you can use two mechanisms to add items to a Combo. The first is to use the add( ) method:

c.add("Item One");
c.add("Item Two");
c.add("Item Three");
c.add("Item Four");
c.add("Item Five");

You can also create an array of String objects to hold the items, then make a single call to setItems( ):

Note

All this is identical to the way List works.

String items[] = {"Item One", "Item Two", "Item Three", "Item Four", 
   "Item Five"};    
c.setItems(items);

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.