This section illustrates you how to create a combo box.
In this example, we have created two different combo boxes where one is performing an action on the second combo box. The items tea , coffee and cold drink are added to the first combo box by using the method add() of Combo class. To perform an action on the second combo box, the class SelectionEvent is called. If you select the cold drink from the first combo box, the array of drinks is added to the second combo box by using the method combo2.setItems(drinks).The method getText().equals("Cold drink") returns the text Cold drink. If you select Tea or Coffee, the second combo box shows the text 'not Applicable'.
Here is the code of ComboBox.java
import java.util.Arrays;
|
Output will be displayed as:

As no value is added for the item tea and coffee, therefore if you select the tea, it will show you Not Applicable on the second combo box.

If you select the cold drink, it will show you select.

After selecting the cold drink, output will be displayed as:

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: How to create Combo Box in SWT View All Comments
Post your Comment