I have a program that builds the GUI in the constructor. I need a Thread separate from the EDT to run immediately after the object in question is constructed. Could anyone point me in the right direction?
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.
What you want to use is a SwingWorker<T,V>. In the
doInBackgroundmethod, open the connection and start fetching data. When you have enough data to update the gui, call thepublishmethod. Implement theprocessmethod to update the gui with the new data frompublish, and finally, implement thedonemethod to notify the user when you’re finished fetching data.The Swing Worker is a generic, so when you construct it you need to provide two types:
TandV.Vis the type for the data passed betweenpublishandprocessmethods andTis the type returned bydoInBackgroundand passed todone.