• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, I'm glad it was an artifact of Thread.sleep - it was used just to create a delay.
 
reply
    Bookmark Topic Watch Topic
  • New Topic