• Post Reply Bookmark Topic Watch Topic
  • New Topic

setting enabled = false on a JButton doesn't work as I expected  RSS feed

 
Nate Lockwood
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Rob Camick
Ranch Hand
Posts: 2788
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Nate Lockwood
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, I'm glad it was an artifact of Thread.sleep - it was used just to create a delay.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!