While trying to achieve the above I managed to get a drop down or drop up list in a different way, with popup ups and menuBar. Hope this helps if you are looking to achieve something similar. While I tried to use a MenuBar instead of a Popup it always lists down which I didn't want. It is definitely nicer when it lists up !! There are other options as well. You can use labels instead of a the menubar. You just have to add the labels in the PopupPanel in a vertical Panel, and define a clickHandler for each Label. Please do update if you have a better solution.
// below PopUp panel to show the options that the user can click
PopupPanel mainPopup = new PopupPanel(true, true);
// Commands to be executed when user clicks the option
Command option1 = new Command() {
@Override
public void execute() {
Window.alert("Option 1");
select.setText("Option 1");
}
};
Command option2 = new Command() {
@Override
public void execute() {
Window.alert("Option 2");
select.setText("Option 1");
}
};
// MenuBar that will contain the options
MenuBar options = new MenuBar(true);
options.addItem("Option 1", option1);
options.addItem("Option 2", option2);
// A Label that triggers the PopUp
Label select = new Label("Select");
// Click handler for the Label
select.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
if (!mainPopup.isShowing()) {
mainPopup.showRelativeTo(select);
} else {
mainPopup.hide();
}
}
});
// finally we add the options to the popup
mainPopup.add(options);
}