Java issue, disabled controls still fire events!

I am new to Java, I am coding NetBeans. The problem is that whenever I turn off the control ie jmenu.setEnabled (false), it still fires events! holy crap! how is it !: P

How can I prevent this?

+3
source share
3 answers

To match the event model adopted by Swing, I believe that your best option is to simply add the isEnabled () check to the handlers that you do not want to execute when the component is disabled.

+2
source

From javadoc :

Note. Disabling the light component does not interfere with receiving MouseEvents.

. . .

, disableEvents ( ).

+7

Consider the use of javax.swing.Action-controlled Swing components.

This way you can disable the action directly with Action.setEnabled. Its component will automatically accept its state. When disabled in this way, the components will not receive MouseEvents.

See documents in the designer JButton(Action).

+1
source

Source: https://habr.com/ru/post/1759672/


All Articles