tags:

views:

67

answers:

3

I'm new to Java, I'm coding on NetBeans. The problem is that whenever I disable a control i.e jmenu.setEnabled(false) it still fires events! holy crap! how is it! :P

How can I prevent it?

+5  A: 

From the javadoc:

Note: Disabling a lightweight component does not prevent it from receiving MouseEvents.

Note: Disabling a heavyweight container prevents all components in this container from receiving any input events. But disabling a lightweight container affects only this container.

You might want to check out disableEvents(long mask).

JRL
thank you, but then, what can i do to prevent the lightweight componenet of receiving event calls in disabled state and still allow the heavyweight container to receive the calls?
Arturo
aaah ok ill check that :D
Arturo
A: 

To fit in with the event model adopted by Swing, I think your best option is to just add a check of isEnabled() in the handlers that you don't want executed when the component is disabled.

Arnold Spence
yea , thought that too;took me a while.programming in c# has got me lazy in low level stuff
Arturo
+1  A: 

Consider using javax.swing.Action-controlled Swing components.

In this way, you can instead disable an Action directly with Action.setEnabled. Its component(s) will adopt its state automatically. When disabled in this manner, the components won't receive MouseEvents.

See the docs on the constructor JButton(Action).

Noel Ang