How can I perform action in background at program start? I would expect some kind of onLoad event for this purpose. Just to be clear: Load ui. Do some stuff and load some more UI based on result of my event.
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.
Have a look at the SwingWorker. Swing is single threaded so any background processing needs to be done from a seperate thread to avoid blocking the swing (event dispatch) thread.
There also no onLoad type functionality available so you’ll need to startup the worker yourself when you initialise your gui.
There are utility method in EventQueue class, invokeLater() and invokeNow() which can be used to update the gui from a different thread. They allow you to specify code to be run on the event dispatch thread.