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

      

enter image description here

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.

+3


source to share


2 answers


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?

http://google-web-toolkit.googlecode.com/svn/javadoc/2.5/com/google/gwt/user/client/ui/PopupPanel.html

+1


source


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.

-1


source







All Articles