I wrote a GUI program, when the program is running(write file), close button is not working, so I cant stop it when it’s running. Anybody know why? And can i stop it(when it’s writting file)?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Without further evidence, I guess you are writing out your file in the context of the Event Dispatching Thread.
This is very, very bad. The EDT is responsible for (amongst other things) processing all the UI events that occur, including the request to close your window. But if you block this thread with time consuming tasks (like I/O, loops,
Thread#sleepor any other blocking operation), then the EDT is unable to process any of the events accumulating in the queue.In this case, you best bet would be to use a
SwingWorkerto off load the writing of the file to another thread. Check out Concurrency in Swing for more information