In this section, you will learn how to create the popup list.
SWT allows to create the popup list by providing the class PopupList of package org.eclipse.swt.custom. In the given example, we are going to popup the list of Indian states. For this, we have create an array of states. The class PopupList create the list. The method setItem() adds the items to the list. The method list.open(shell.getBounds()) opens the list and get the selected item. The Button class is used to create the button to perform an action by calling the class SelectionEvent.
To display the selected state, we have used the class Text which creates the textBox with the button. As the button is clicked, the list will be displayed. On selecting the state, the method text.setText("Selected:"+selected) sets the selected state on the textBox. The method text.setSize() sets the size of textBox.
Here is the code of PopupListExample.java
Output will be displayed as:
On clicking the button, list will be displayed:
On selecting the state, output will be displayed as:
Liked it! Share this Tutorial