Is this your first time here? SwingWiki is a Java Swing Developer community site with an big archive of Swing-related usenet groups and mailing lists, but also tips, tricks and articles and book reviews written by your colleagues from around the world. If you came here through a search engine and did not find what you were looking for, make sure to check the wiki table of contents.

Block components during threaded event handling

If you are starting a new thread to process an event (perhaps to show background animations, or to keep the GUI responsive), always remember to block controlling components (for example buttons), so that your users won’t surprise you by clicking two times on the same button, or generating another action while the current processing is not yet finished. The best time to block components is right before the start of a new thread.

If you block components in a new thread, users will still theoretically be able to push the button twice. Once the event handler finishes, enable the components in the processing thread.

This is also a good model for showing the busy cursor - change the cursor before you start a new thread, and change it back on the end of event processing in that thread. See Cursor Change Not Working for an example.

If you are not familiar with Swing Multi-threading issues, read Swing Threading first.


Comments? Corrections? Contact us or Login to edit pages directly (registration is free and takes less than displaying a JLabel)
  best/block_components_during_threaded_event_handling.txt · Last modified: 2005/02/14 10:50
Recent changes | RSS changes | Table of contents | News Archive | Terms And Conditions | Register | The Quest For Software++| Ruby Resources

Sedo - Buy and Sell Domain Names and Websites project info: Statistics for project etracker� web controlling instead of log file analysis