How do I remove the GWT menu from the screen?
I am starting to use GWT. I have menubar
one that appears on Label click
. I need to remove it when the user clicks anywhere on the screen other than the shortcut that made it display (Legal). I have tried various methods like hooking this event on
RootPanel.get().addDomHandler(clickDetectHandler, ClickEvent.getType());
public void onClick(ClickEvent event) {
Object source = event.getSource();
if (!(source instanceof MenuBar))
panel.remove(menu);
I even tried using MouseOutEvent
it but didn't find the click. I can remove it by clicking on legal label
. But I need it to be removed when a click is detected on the screen. Please advise.
source to share
GWT has a PopupPanel that automatically handles exactly the behavior you want. Quoting from the javadoc:
"The PopupPanel constructor accepts" auto-hide "as its boolean parameter. If set, the panel will automatically close when the user clicks on it."
Is it possible for the popup menu to appear inside the PopupPanel?
source to share
Check out this GWT sample. This is similar to the behavior you are describing. It comes with source code.
Alternatively, you can try handling blurring events in menu widgets.
source to share