My code is:
solveDb_userfileInconsistency solve = new solveDb_userfileInconsistency();
solve.setVisible(true);
try {
solve.solveIt();
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
"solveIt" method returns after 30 seconds and until it returns, frame isn't installed properly but after solveIt method returns, the frame gets installed properly but what i want is that before going into solveIt method, the frame should be properly on the screen. Is there any method that can wait the frame's installation and then calls that solveIt method?
It sounds like you're probably doing all of this on the UI thread. Don't do that - make solveIt
execute on a background thread, calling into the UI thread using SwingUtilities
if it needs to update/query the UI. Basically, you shouldn't do significant work in the UI thread - see the Swing concurrency tutorial for more information.
Take a look at SwingWorker Class. It is used to do the background processes without stopping the frame to be installed.
Use the event-dispatching thread for short lived GUI related code. Long running tasks should be execute in their own threads as proposed in the other answers.
Since people bet me to it. Let me just complement their answers with some interesting links:
Note that the two links points to somewhat old but relevant documentation of JFC. Nowadays SwingWorker
is included in the Standard API.
Cheers,
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With