It doesn't look like there is any direct support for receiving a notification once the button has been clicked, but before the menu has been opened. Adding a ButtonPressListener to the MenuButton wouldn't really be any better than listening for the windowOpened event.
(ListButton behaves in the same way) If you *did* need notification after the click, but before the window opened, I think it would require a custom skin to override org.apache.pivot.wtk.skin.MenuButtonSkin.mouseDown(Component, Button, int, int) org.apache.pivot.wtk.skin.MenuButtonSkin.keyPressed(Component, int, KeyLocation) Perhaps org.apache.pivot.wtk.MenuHandler needs a new configureMenuButton() method equivalent to configureContextMenu()? A MenuHandler property could then be added to MenuButton. Chris On 24 June 2011 16:27, Edvin Syse <[email protected]> wrote: > Den 24.06.2011 11:17, skrev Edvin Syse: > > I have a MenuButton where I want to create the menu dynamically before >> each time it is shown. Where should I attach a listener, and how should I >> populate the menu each time? >> > This seems to work, but is it the correct approach? > > menuButton.getListPopup().getWindowStateListeners().add(new > WindowStateListener.Adapter() { > public void windowOpened(Window window) { > Menu menu = new Menu(); > // Add sections and items > menuButton.setMenu(menu); > super.windowOpened(window); > } > }); > > -- Edvin >
