2

I want to if it is possible to disable the auto-close MenuBar when I click on a MenuItem? I have several MenuItem that are like checkboxes, so I can check more than one MenuItem and don't want my menu close everytime I checked one.

Thanks.

TiGi
  • 115
  • 2
  • 9
  • 1
    I can't figure out how to prevent a MenuBar from closing when selecting an Item, or how to open a MenuBar programmatically. It seems like something that should be included though. You may just have to make your own "MenuBar" that uses [Popup Panels](http://google-web-toolkit.googlecode.com/svn/javadoc/2.3/com/google/gwt/user/client/ui/PopupPanel.html) as bad as that sounds. – Jay Jul 08 '11 at 15:50

3 Answers3

0

I was facing same problem and I will share with you my solution:

1) Create new class MyMenuItemWithCheckBox that extends the MenuItem. In the constructor set element ID to (forexample) menuItemWIthCheckBox + Unique text. this.getElement().setId("menuItemWithCheckBox_" + menuItemLabel);

2) Create new class MyMenuBar that extends the MenuBar. Override the onBrowserEvent method by following:

Override
    public void onBrowserEvent(Event event) {
        if (DOM.eventGetType(event) == Event.ONCLICK && getSelectedItem().getElement().getId().contains("CheckBox")) {
            Scheduler.get().scheduleFinally(new Scheduler.ScheduledCommand() {
                @Override
                public void execute() {
                    getSelectedItem().getScheduledCommand().execute();
                }
            });

            event.stopPropagation();
        } else {
            super.onBrowserEvent(event);
        }
    }

Now scheduled command of MenuItem is always called, but in the case of your menu checkBox item there is no close of a menubar.

I hope this help you, I spend more than day to create this solution. :-)

Marek
  • 1
-1

You can set hideOnClick to false on the menuItems

See here.

j0k
  • 22,600
  • 28
  • 79
  • 90
-1

First, directly it's not possible because the popup-panel which displays the submenu is private in the MenuBar class.

Buuut, there is a way to do so ...

Simpley fetch the current MenuBar.java code out of googles code repository and include it in your eclipse gwt-project.

You don't have to change anything e.g. package deklaration or something. Just put your source in your project and it will simply replace the original MenuBar-class from the gwt-sdk during compilation (works also with hosted development mode).

Then you can simply set the property autoHide of the popup-Panel to false and the popup shouldn't disappear after clicking.

thomas
  • 164
  • 1
  • 2