The code is doing the right thing. If you assign an action to a button, you should use the action to manage the button's enabled state, not setEnabled().
On May 4, 2011, at 10:16 AM, Sandro Martini wrote: > Hi Greg, > if i add this > > whatIsThisMenuItem.setEnabled(false); > > after the line > > whatIsThisMenuItem.setAction(new Action() { > ... > }); > > at runtime I get this exception: > > java.lang.IllegalArgumentException: Button and action enabled states are not > consistent. > at org.apache.pivot.wtk.Button.setEnabled(Button.java:401) > at org.apache.pivot.wtk.Menu$Item.setEnabled(Menu.java:90) > at > org.apache.pivot.tutorials.menus.ContextMenus$1.configureContextMenu(ContextMenus.java:53) > at > org.apache.pivot.wtk.ApplicationContext$DisplayHost.processMouseEvent(ApplicationContext.java:858) > at java.awt.Component.processEvent(Component.java:6054) > at > org.apache.pivot.wtk.ApplicationContext$DisplayHost.processEvent(ApplicationContext.java:709) > at java.awt.Component.dispatchEventImpl(Component.java:4652) > at java.awt.Component.dispatchEvent(Component.java:4482) > at > java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577) > at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4235) > at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168) > at java.awt.Container.dispatchEventImpl(Container.java:2085) > at java.awt.Window.dispatchEventImpl(Window.java:2478) > at java.awt.Component.dispatchEvent(Component.java:4482) > at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:644) > at java.awt.EventQueue.access$000(EventQueue.java:85) > at java.awt.EventQueue$1.run(EventQueue.java:603) > at java.awt.EventQueue$1.run(EventQueue.java:601) > at java.security.AccessController.doPrivileged(Native Method) > at > java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87) > at > java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98) > at java.awt.EventQueue$2.run(EventQueue.java:617) > at java.awt.EventQueue$2.run(EventQueue.java:615) > at java.security.AccessController.doPrivileged(Native Method) > at > java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87) > at java.awt.EventQueue.dispatchEvent(EventQueue.java:614) > at > java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269) > at > java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184) > at > java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174) > at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169) > at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161) > at java.awt.EventDispatchThread.run(EventDispatchThread.java:122) > > note that in my case in my contextual menu now I have added other items (one > before this item, and another after, just for example) , so I don't know it > it's good to have this exception. > > But in any case I think that the issue is the following: > if I add the same line but just before the setAction, i get no exception, > and the related item is selectable and the action is executed ... > > I see that in the > public void perform(Component source) { > source is the Menu.Item, but as inspected by the debugger it has enabled = > true (and that's strange) ... and probably should be fixed, and the caller > of perform should call it only if source is enabled, ok ? > Than as a workaround I suggest to check if source is enabled, otherwise do > nothing (and maybe close the context menu). > > What do you think ? > > Bye, > Sandro > > > -- > View this message in context: > http://apache-pivot-developers.417237.n3.nabble.com/jira-Created-PIVOT-737-TerraTableViewSkin-opens-a-TableViewRowEditor-listening-to-both-mouse-buttons-tp2871532p2899010.html > Sent from the Apache Pivot - Developers mailing list archive at Nabble.com.