Alternative to Drop Down List Box !

293 views
Skip to first unread message

BST

unread,
Jul 29, 2011, 8:39:02 AM7/29/11
to google-we...@googlegroups.com

I just wanted to update on the Drop Down List Box, 

GWT Incubator
Drop Down List BoxNot planned at this time, but some people use a vertical MenuBar to achieve the same effect


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);
}


** I wish there was a code box widget here :-) so that I can easily show the code I want in a preformatted way. ***


Reply all
Reply to author
Forward
0 new messages