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
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:
Liked it! Share this Tutorial