V
V
VasG2011-11-11 21:23:20
Java
VasG, 2011-11-11 21:23:20

In Java (Swing), the element is clickable even though it is set to setEnabled(false). What to do?



Actually, the whole question is in the title and video ...
The button, which, at the time of loading and preprocessing, should be inactive, continues to respond to mouse clicks, although it is explicitly told: button.setEnabled(false); The button fires on a mouse click, but exactly the same thing happens with onMousePressed.
A lot of unnecessary threads begin to multiply, an abnormal amount of memory is “guzzled” and other obvious inconveniences ...
How to avoid this?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
K
kindcoder, 2011-11-12
@VasG

Note: Disabling a lightweight component does not prevent it from receiving MouseEvents.
JavaDoc
Therefore, ertaquo is right - you need to check the activity in the handler.

A
Anatoly, 2011-11-12
@taliban

What an epic ending in a video =)

E
ertaquo, 2011-11-12
@ertaquo

Can additionally check the activity of the button in the click handler?

A
Alexey Kamchatkin, 2011-11-12
@PoN

Is the listener defined correctly? and what event are you "listening" to?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question