You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pivot.apache.org by Edvin Syse <ed...@sysedata.no> on 2011/06/24 11:17:07 UTC

How to create menu for MenuButton dynamically

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?

-- Edvin

Re: How to create menu for MenuButton dynamically

Posted by Edvin Syse <ed...@sysedata.no>.
Den 24.06.2011 18:20, skrev Greg Brown:
>> (why do I have to be concerned that there
>> is a Window involved, when all I want to do is populate a menu?)
>
> This use case isn't limited to menus. As you noted, it applies to any type of button that displays a popup (such as list buttons). Since a popup is just a window, I think it makes sense to use the window events to handle it.
>
>> However, if the previewWindowOpen event does not make a comeback (and I
>> assume it was removed for a reason)
>
> No reason. We just didn't think there was a use case for it. But it now seems like there is.

I created an issue with a patch now:

https://issues.apache.org/jira/browse/PIVOT-765

-- Edvin

Re: How to create menu for MenuButton dynamically

Posted by Greg Brown <gk...@verizon.net>.
> (why do I have to be concerned that there
> is a Window involved, when all I want to do is populate a menu?)

This use case isn't limited to menus. As you noted, it applies to any type of button that displays a popup (such as list buttons). Since a popup is just a window, I think it makes sense to use the window events to handle it.

> However, if the previewWindowOpen event does not make a comeback (and I
> assume it was removed for a reason)

No reason. We just didn't think there was a use case for it. But it now seems like there is.



Re: How to create menu for MenuButton dynamically

Posted by Chris Bartlett <cb...@gmail.com>.
(continued just to dev list)

On 24 June 2011 22:32, Greg Brown <gk...@verizon.net> wrote:

> The MenuHandler interface is generic - it applies to all components and is
> provided as a convenience for configuring either:
>
> a) a component-specific context ("right-click") menu
> b) an application-wide frame menu bar
>
> I don't understand how "configureMenuButton()" would fit into that model.
> All components can have a context menu, and all components may be
> descendants of a frame that has a menu bar. However, components don't "have"
> a menu button, so it's not clear what menu button
> MenuHandler#configureMenuButton() would apply to, or when/how it would be
> triggered.
>
> Yes, I agree that it is not a fit to the model you describe although I
hadn't even it that before you mentioned it.  (And obviously hadn't picked
up on how MenuHandler fits into the grand scheme of things)

My point was that as Pivot consumers, both Edvin and myself looked at the
MenuHandler class, as its name suggested it might be used in conjunction
with a MenuButton somehow.  Combined with the knowledge that context menus
can be configured before they are displayed, I thought there would be an
equivalent mechanism *somewhere* for configuring the menu of a MenuButton
before it is displayed.


If I understand you correctly, I think what you are describing might be a
> new event or handler on MenuButton itself. For example, MenuButton could
> fire a "menu about to be shown" or "menu hidden" event that a caller could
> hook and use to populate/tear down the menu's contents.
>
> Yes, that is pretty much what I was describing, but only in an effort to
provide a dedicated means of configuring a context menu before it is
displayed.
Context menu --> MenuHandler  (of course!)
MenuButton --> WindowStateListener (why do I have to be concerned that there
is a Window involved, when all I want to do is populate a menu?)  I
understand that this is not a big deal - I just thought there would be a
cleaner way.

However, the window open preview and window close events map well to this
> scenario, so I'm not sure how much value there would be in creating new
> events specifically for this purpose.
>
The idea of some kind of configureMenuButton() callback came up before the
proposed reintroduction of the previewWindowOpen stuff.  If the
previewWindowOpen goes ahead, then there would obviously be no need for an
additional event that essentially achieves the same thing.

However, if the previewWindowOpen event does not make a comeback (and I
assume it was removed for a reason), then some other event specifically for
the purpose of configuring a MenuButton could be possible, or even one
common to all components that 'pop up a Window'. A 'PopupStateListener' for
want of a better name.

Chris



>
> On Jun 24, 2011, at 11:19 AM, Chris Bartlett wrote:
>
> > I'll try rephrasing.
> >
> > Although I hadn't used MenuButtons before, I was aware of the MenuHandler
> interface.
> > As the name suggested it handled Menus, I thought it would define some
> kind of a configureMenuButton() method similar to configureMenuBar() and
> configureContextMenu().
> > This is purely based on the class names - MenuBar & MenuButton.
> >
> > My expectation was that *if* such a method existed, it would be used to
> configure the menu to be displayed by a MenuButton prior to the MenuButton's
> popup opening.
> >
> > *If* a MenuHandler implementation contained such a method, I would only
> expect that method to be executed in the above scenario, ie when that menu
> handler was set for a MenuButton instance.  It would simply be ignored for
> any other Components.
> >
> >
> > I just expected a callback similar to
> configureContextMenu/configureMenuBar to exist *somewhere*, and be designed
> for use in the scenario Edvin described.  Perhaps it would be defined in a
> MenuButton.Handler interface, but the generic 'MenuHandler' name suggested
> that would  be the obvious place to look.  Edvin mentioned early on in the
> thread that it was where he looked too.
> >
> > All of this derives from my take on the general consistency throughout
> Pivot.
> >
> > Chris
> >
> > On 24 June 2011 21:55, Greg Brown <gk...@verizon.net> wrote:
> > > When Edvin asked the question, my first thought was that MenuButton
> probably had setMenuHandler() method, and MenuHandler had a corresponding
> configureMenuButton() method.
> > >
> > > Following activation of the MenuButton, the configureMenuButton() would
> be called to populate the menu
> >
> > OK, but a menu button can be attached to any component. What would it do
> for non-MenuButton components?
> >
> >
> >
>
>

Re: How to create menu for MenuButton dynamically

Posted by Greg Brown <gk...@verizon.net>.
The MenuHandler interface is generic - it applies to all components and is provided as a convenience for configuring either:

a) a component-specific context ("right-click") menu
b) an application-wide frame menu bar

I don't understand how "configureMenuButton()" would fit into that model. All components can have a context menu, and all components may be descendants of a frame that has a menu bar. However, components don't "have" a menu button, so it's not clear what menu button MenuHandler#configureMenuButton() would apply to, or when/how it would be triggered.

If I understand you correctly, I think what you are describing might be a new event or handler on MenuButton itself. For example, MenuButton could fire a "menu about to be shown" or "menu hidden" event that a caller could hook and use to populate/tear down the menu's contents. However, the window open preview and window close events map well to this scenario, so I'm not sure how much value there would be in creating new events specifically for this purpose.

G

On Jun 24, 2011, at 11:19 AM, Chris Bartlett wrote:

> I'll try rephrasing.
> 
> Although I hadn't used MenuButtons before, I was aware of the MenuHandler interface.
> As the name suggested it handled Menus, I thought it would define some kind of a configureMenuButton() method similar to configureMenuBar() and configureContextMenu().
> This is purely based on the class names - MenuBar & MenuButton.
> 
> My expectation was that *if* such a method existed, it would be used to configure the menu to be displayed by a MenuButton prior to the MenuButton's popup opening.  
> 
> *If* a MenuHandler implementation contained such a method, I would only expect that method to be executed in the above scenario, ie when that menu handler was set for a MenuButton instance.  It would simply be ignored for any other Components.
> 
> 
> I just expected a callback similar to configureContextMenu/configureMenuBar to exist *somewhere*, and be designed for use in the scenario Edvin described.  Perhaps it would be defined in a MenuButton.Handler interface, but the generic 'MenuHandler' name suggested that would  be the obvious place to look.  Edvin mentioned early on in the thread that it was where he looked too.
> 
> All of this derives from my take on the general consistency throughout Pivot.  
> 
> Chris
> 
> On 24 June 2011 21:55, Greg Brown <gk...@verizon.net> wrote:
> > When Edvin asked the question, my first thought was that MenuButton probably had setMenuHandler() method, and MenuHandler had a corresponding configureMenuButton() method.
> >
> > Following activation of the MenuButton, the configureMenuButton() would be called to populate the menu
> 
> OK, but a menu button can be attached to any component. What would it do for non-MenuButton components?
> 
> 
> 


Re: How to create menu for MenuButton dynamically

Posted by Greg Brown <gk...@verizon.net>.
The MenuHandler interface is generic - it applies to all components and is provided as a convenience for configuring either:

a) a component-specific context ("right-click") menu
b) an application-wide frame menu bar

I don't understand how "configureMenuButton()" would fit into that model. All components can have a context menu, and all components may be descendants of a frame that has a menu bar. However, components don't "have" a menu button, so it's not clear what menu button MenuHandler#configureMenuButton() would apply to, or when/how it would be triggered.

If I understand you correctly, I think what you are describing might be a new event or handler on MenuButton itself. For example, MenuButton could fire a "menu about to be shown" or "menu hidden" event that a caller could hook and use to populate/tear down the menu's contents. However, the window open preview and window close events map well to this scenario, so I'm not sure how much value there would be in creating new events specifically for this purpose.

G

On Jun 24, 2011, at 11:19 AM, Chris Bartlett wrote:

> I'll try rephrasing.
> 
> Although I hadn't used MenuButtons before, I was aware of the MenuHandler interface.
> As the name suggested it handled Menus, I thought it would define some kind of a configureMenuButton() method similar to configureMenuBar() and configureContextMenu().
> This is purely based on the class names - MenuBar & MenuButton.
> 
> My expectation was that *if* such a method existed, it would be used to configure the menu to be displayed by a MenuButton prior to the MenuButton's popup opening.  
> 
> *If* a MenuHandler implementation contained such a method, I would only expect that method to be executed in the above scenario, ie when that menu handler was set for a MenuButton instance.  It would simply be ignored for any other Components.
> 
> 
> I just expected a callback similar to configureContextMenu/configureMenuBar to exist *somewhere*, and be designed for use in the scenario Edvin described.  Perhaps it would be defined in a MenuButton.Handler interface, but the generic 'MenuHandler' name suggested that would  be the obvious place to look.  Edvin mentioned early on in the thread that it was where he looked too.
> 
> All of this derives from my take on the general consistency throughout Pivot.  
> 
> Chris
> 
> On 24 June 2011 21:55, Greg Brown <gk...@verizon.net> wrote:
> > When Edvin asked the question, my first thought was that MenuButton probably had setMenuHandler() method, and MenuHandler had a corresponding configureMenuButton() method.
> >
> > Following activation of the MenuButton, the configureMenuButton() would be called to populate the menu
> 
> OK, but a menu button can be attached to any component. What would it do for non-MenuButton components?
> 
> 
> 


Re: How to create menu for MenuButton dynamically

Posted by Chris Bartlett <cb...@gmail.com>.
I'll try rephrasing.

Although I hadn't used MenuButtons before, I was aware of the MenuHandler
interface.
As the name suggested it handled Menus, I thought it would define some kind
of a configureMenuButton() method similar to configureMenuBar() and
configureContextMenu().
This is purely based on the class names - MenuBar & MenuButton.

My expectation was that *if* such a method existed, it would be used to
configure the menu to be displayed by a MenuButton prior to the MenuButton's
popup opening.

*If* a MenuHandler implementation contained such a method, I would only
expect that method to be executed in the above scenario, ie when that menu
handler was set for a MenuButton instance.  It would simply be ignored for
any other Components.


I just expected a callback similar to configureContextMenu/configureMenuBar
to exist *somewhere*, and be designed for use in the scenario Edvin
described.  Perhaps it would be defined in a MenuButton.Handler interface,
but the generic 'MenuHandler' name suggested that would  be the obvious
place to look.  Edvin mentioned early on in the thread that it was where he
looked too.

All of this derives from my take on the general consistency throughout
Pivot.

Chris

On 24 June 2011 21:55, Greg Brown <gk...@verizon.net> wrote:

> > When Edvin asked the question, my first thought was that MenuButton
> probably had setMenuHandler() method, and MenuHandler had a corresponding
> configureMenuButton() method.
> >
> > Following activation of the MenuButton, the configureMenuButton() would
> be called to populate the menu
>
> OK, but a menu button can be attached to any component. What would it do
> for non-MenuButton components?
>
>
>

Re: How to create menu for MenuButton dynamically

Posted by Greg Brown <gk...@verizon.net>.
> When Edvin asked the question, my first thought was that MenuButton probably had setMenuHandler() method, and MenuHandler had a corresponding configureMenuButton() method.
> 
> Following activation of the MenuButton, the configureMenuButton() would be called to populate the menu

OK, but a menu button can be attached to any component. What would it do for non-MenuButton components?



Re: How to create menu for MenuButton dynamically

Posted by Chris Bartlett <cb...@gmail.com>.
When Edvin asked the question, my first thought was that MenuButton probably
had setMenuHandler() method, and MenuHandler had a corresponding
configureMenuButton() method.

Following activation of the MenuButton, the configureMenuButton() would be
called to populate the menu

On 24 June 2011 21:03, Greg Brown <gk...@verizon.net> wrote:

> > What do you think about adding an extra method into the MenuHandler
> interface to configure MenuButtons?
>
> Can you describe more specifically what you are envisioning? Context menus
> apply to an individual component, each of which may belong to at most one
> Frame (which provides the menu bar). How would menu buttons fit into that?
>
>
>

Re: How to create menu for MenuButton dynamically

Posted by Greg Brown <gk...@verizon.net>.
> What do you think about adding an extra method into the MenuHandler interface to configure MenuButtons?  

Can you describe more specifically what you are envisioning? Context menus apply to an individual component, each of which may belong to at most one Frame (which provides the menu bar). How would menu buttons fit into that?



Re: How to create menu for MenuButton dynamically

Posted by Chris Bartlett <cb...@gmail.com>.
On 24 June 2011 19:26, Edvin Syse <ed...@sysedata.no> wrote:

> I still kind of feel like I should be able to use a MenuHandler to populate
> my Menu, that was my first attempt, because it seemed logical and in line
> with everything else :)
>

Greg,

What do you think about adding an extra method into the MenuHandler
interface to configure MenuButtons?  I agree with Edvin that it seems like a
logical place, especially as it already supports MenuBars and context menus.

I don't have a problem with the re-introduction of the previewWindowOpen()
event due to its flexibility. For instance it could also be used with other
popup components such as ListButton.

Chris

Re: How to create menu for MenuButton dynamically

Posted by Edvin Syse <ed...@sysedata.no>.
Den 24.06.2011 14:57, skrev Greg Brown:
> FYI, the original code can still be found under the 1.5 tag in SVN.
Argfl, I just re-implemented it and created a patch, testing it now :) 
hehe..

-- Edvin

Re: How to create menu for MenuButton dynamically

Posted by Greg Brown <gk...@verizon.net>.
>> Yes, patches should always be submitted via JIRA.
>> I'll take a look.
> Feels good to have someone look over it before I create the JIRA ticket, but I guess as time goes and I get to know the code base better I'll feel more comfortable with adding tickets without bothering you guys first :)

I think it works best to propose and discuss a potential change on the mailing list, but then review and discuss the patch in JIRA. But that's just my opinion.

G


Re: How to create menu for MenuButton dynamically

Posted by Edvin Syse <ed...@sysedata.no>.
Den 24.06.2011 15:28, skrev Greg Brown:
> We don't use wildcard imports in the Pivot codebase since it tends to 
> obscure the classes that are actually being used (makes it harder to 
> understand what is going on if you are not familiar with the code). 
> Also, my understanding is that there is minimal performance benefit to 
> import *.
I totally agree. Changing my setup :)

> Yes, patches should always be submitted via JIRA.
> I'll take a look.
Feels good to have someone look over it before I create the JIRA ticket, 
but I guess as time goes and I get to know the code base better I'll 
feel more comfortable with adding tickets without bothering you guys 
first :)

-- Edvin

Re: How to create menu for MenuButton dynamically

Posted by Greg Brown <gk...@verizon.net>.
> Basically, it removes redundant imports, but it also "compresses", if you have more than X imports for the same package, it will remove all those and import package.* instead.

We don't use wildcard imports in the Pivot codebase since it tends to obscure the classes that are actually being used (makes it harder to understand what is going on if you are not familiar with the code). Also, my understanding is that there is minimal performance benefit to import *.

>>> I guess the patch should touch as little as possible when it doesn't have to do with the actual functionality right?
>> Yes, minimizing the surface area of a patch is always good since it makes it easier to see the non-trivial changes.
> OK, I understand. Here is my patch, without the IDEA wizardry :) Should I create an issue and refer to the usecase in this thread?

Yes, patches should always be submitted via JIRA.

> PS: As you know, I have no deep knowledge of Pivot yet, but this seemed very clear cut. I might have missed something though... I basically added the methods, made sure Window#open calls the listeners and if voted down, respects the Veto and notifies listeners about the veto. I added default implementations to the Adapter and let implementations use the Adapter where appropriate.

I'll take a look.


Re: How to create menu for MenuButton dynamically

Posted by Edvin Syse <ed...@sysedata.no>.
Den 24.06.2011 15:16, skrev Greg Brown:
>> My patch seems to work good, but I see that I have IntelliJ IDEA setup to optimize imports.
> What do you mean by "optimize imports"?
http://www.jetbrains.com/idea/webhelp/optimizing-imports.html

Basically, it removes redundant imports, but it also "compresses", if 
you have more than X imports for the same package, it will remove all 
those and import package.* instead.

>> I guess the patch should touch as little as possible when it doesn't have to do with the actual functionality right?
> Yes, minimizing the surface area of a patch is always good since it makes it easier to see the non-trivial changes.
OK, I understand. Here is my patch, without the IDEA wizardry :) Should 
I create an issue and refer to the usecase in this thread? PS: As you 
know, I have no deep knowledge of Pivot yet, but this seemed very clear 
cut. I might have missed something though... I basically added the 
methods, made sure Window#open calls the listeners and if voted down, 
respects the Veto and notifies listeners about the veto. I added default 
implementations to the Adapter and let implementations use the Adapter 
where appropriate.

-- Edvin

Re: How to create menu for MenuButton dynamically

Posted by Greg Brown <gk...@verizon.net>.
> My patch seems to work good, but I see that I have IntelliJ IDEA setup to optimize imports.

What do you mean by "optimize imports"?

> I guess the patch should touch as little as possible when it doesn't have to do with the actual functionality right?

Yes, minimizing the surface area of a patch is always good since it makes it easier to see the non-trivial changes.


Re: How to create menu for MenuButton dynamically

Posted by Edvin Syse <ed...@sysedata.no>.
My patch seems to work good, but I see that I have IntelliJ IDEA setup 
to optimize imports. I guess that kind of stuff is frovned upon when 
creating patches.. Are there any guidelines on the topic, or what do you 
say about the practice? I guess the patch should touch as little as 
possible when it doesn't have to do with the actual functionality right?

-- Edvin

Re: How to create menu for MenuButton dynamically

Posted by Greg Brown <gk...@verizon.net>.
FYI, the original code can still be found under the 1.5 tag in SVN.

On Jun 24, 2011, at 8:33 AM, Greg Brown wrote:

>>> We actually used to have an open preview event in addition to close preview. An open preview event would solve this problem, since you could populate your menu in response to that event.
>> Why was it removed?
> 
> We didn't think there was a use case for it.
> 
>> Would it be a good idea to reintroduce it?
> 
> Since there actually does seem to be a use case for it, I would say yes.  :-)
> 
>> This is not a big issue for me, I can live with a workaround for now, but it would be nice for "completeness".
> 
> I agree.
> 
> 


Re: How to create menu for MenuButton dynamically

Posted by Greg Brown <gk...@verizon.net>.
>> We actually used to have an open preview event in addition to close preview. An open preview event would solve this problem, since you could populate your menu in response to that event.
> Why was it removed?

We didn't think there was a use case for it.

> Would it be a good idea to reintroduce it?

Since there actually does seem to be a use case for it, I would say yes.  :-)

> This is not a big issue for me, I can live with a workaround for now, but it would be nice for "completeness".

I agree.



Re: How to create menu for MenuButton dynamically

Posted by Edvin Syse <ed...@sysedata.no>.
> We actually used to have an open preview event in addition to close 
> preview. An open preview event would solve this problem, since you 
> could populate your menu in response to that event.
Why was it removed? Would it be a good idea to reintroduce it? I still 
kind of feel like I should be able to use a MenuHandler to populate my 
Menu, that was my first attempt, because it seemed logical and in line 
with everything else :)

This is not a big issue for me, I can live with a workaround for now, 
but it would be nice for "completeness".

-- Edvin

Re: How to create menu for MenuButton dynamically

Posted by Chris Bartlett <cb...@gmail.com>.
On 24 June 2011 19:13, Greg Brown <gk...@verizon.net> wrote:

> We actually used to have an open preview event in addition to close preview
>
>
And there I was thinking I was losing my mind when I couldn't find it! :)

Re: How to create menu for MenuButton dynamically

Posted by Greg Brown <gk...@verizon.net>.
> On 24 June 2011 17:08, Edvin Syse <ed...@sysedata.no> wrote:
> 
> Perhaps org.apache.pivot.wtk.MenuHandler needs a new configureMenuButton() method equivalent to configureContextMenu()?
> A MenuHandler property could then be added to MenuButton.
> 
> I think that would be a good idea. With my current approach I sometimes end up with a menu that is rendered partly outside of the Window. Can I somehow reposition it?
> 
> I haven't tried, but I imagine that some combination of invalidate/repaint calls on the pop up window should do it.  
> Perhaps invalidate the window and repaint in the windowOpened listener, after you have configured the menu?

At first, I thought the idea of listening for the open event was OK, but after looking at the code I'm not sure that it is. TerraMenuButtonSkin also listens for the open event and repositions the popup when it is fired. Since the skin will probably get the event before your code, it is attempting to position an empty window. To fix this, it would need to queue a callback to position the window. That could result in flicker as the window is resized/repositioned.

We actually used to have an open preview event in addition to close preview. An open preview event would solve this problem, since you could populate your menu in response to that event.

G


Re: How to create menu for MenuButton dynamically

Posted by Chris Bartlett <cb...@gmail.com>.
On 24 June 2011 17:08, Edvin Syse <ed...@sysedata.no> wrote:

>
> Perhaps org.apache.pivot.wtk.MenuHandler needs a new configureMenuButton()
> method equivalent to configureContextMenu()?
> A MenuHandler property could then be added to MenuButton.
>
> I think that would be a good idea. With my current approach I sometimes end
> up with a menu that is rendered partly outside of the Window. Can I somehow
> reposition it?
>

I haven't tried, but I imagine that some combination of invalidate/repaint
calls on the pop up window should do it.
Perhaps invalidate the window and repaint in the windowOpened listener,
after you have configured the menu?

Chris

Re: How to create menu for MenuButton dynamically

Posted by Edvin Syse <ed...@sysedata.no>.
Den 24.06.2011 11:48, skrev Chris Bartlett:
> 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.

I think that would be a good idea. With my current approach I sometimes 
end up with a menu that is rendered partly outside of the Window. Can I 
somehow reposition it?

I actually tried adding a MenuHandler first, but ofcourse that didn't 
work :)

-- Edvin

Re: How to create menu for MenuButton dynamically

Posted by Chris Bartlett <cb...@gmail.com>.
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 <ed...@sysedata.no> 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
>

Re: How to create menu for MenuButton dynamically

Posted by Edvin Syse <ed...@sysedata.no>.
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