How to disable Component but let the related ContextMenu enabled?

Hi, I have a button with a ContextMenu applied to it. With certain event, I want to disable the button, so when the user left click on it, nothing happens. However, the right click is also disabled, and I don't want that! How can I do to let the context menu enabled? overriding some methods, perhaps?
Thanks

Anibal

ScoPi's picture

I believe your only

I believe your only solution--which isn't a bad one--is to simply remove all of your ActionListeners while you want the button to be disabled and then add them back when you want the button to be enabled again. In this way, whatever actions normally occur when the listeners are notified won't occur. You can get around the visual changes that occur to the button when pressed by tweaking things through methods like setPressedEnabled() or setPressedBorder(), etc. For example, when the button is "disabled", call setPressedEnabled(false).

Hope this helps.

I can see you're thinking :)

I can see you're thinking :) . I like your solution, simple and clean. I'll try it this afternoon.
Thank you so much!

Just for the record if

Just for the record if someone has the same problem. Finally, what I did is put the button inside a panel and the contextmenu applied to the panel. That way, If I disable the button, the context menu is still enabled.
Thanks ScoPi for the guidance into lateral thinking!

tliebeck's picture

Are you using an Echo3

Are you using an Echo3 Extras context menu? I thought the Context menu would still work even if the (child) button was disabled, but I could be wrong.

Yes, I'm using the Echo3

Yes, I'm using the Echo3 Extras' context menu - b8. However, I'm using composite components in my project, and the component where I was experiencing the problem it's a particular complex one. Maybe I've made a mistake somewhere in the code! I'll take a look at the changelog later and let you know. Thank you!