[Logo]
Forums Register Login
setting enabled = false on a JButton doesn't work as I expected
I new at Java and am just starting with Swing to make a simple but useful GUI tool for me. My "let's test concepts first" GUI has two buttons and first displays with one enabled and the other not.
After the user clicks on the enabled button "btnClickMe" the other button "btnFoo" is enabled. Clicking on btnFoo disables btnClickMe and to simulate doing something, the thread sleeps. If I click on the disabled button while the thread is sleeping nothing happens until sleep times ou and then the click is processed. This behavior was not expected or desired. I assume I'm doing something wrong Would someone elucidate? This is a short class and I can provide the whole thing but here are the relavent methods.

 
Clicking on btnFoo disables btnClickMe and to simulate doing something, the thread sleeps


you should never use Thread.sleep on the Event Dispatch Thread. Code in an event listener automatically execute on the EDT.

Read the section from the Swing tutorial on Concurrency for more information.
Thanks, I'm glad it was an artifact of Thread.sleep - it was used just to create a delay.
Wink, wink, nudge, nudge, say no more ... https://richsoil.com/cards



All times above are in ranch (not your local) time.
The current ranch time is
Dec 12, 2017 09:09:19.