Re: GUI Lockup during run
GUI lockups are usually caused by having your code execute on Swing's Event Dispatcher Thread.
If you have a long task you want to run, you need to have it execute on its own thread and leave the GUI thread free for Swing.
Re: GUI Lockup during run
Re: GUI Lockup during run
Look for some sample code here or on other forums that use Thread or SwingWorker. Or read the Java Tutorial.
Basically you create a Thread with a Runnable and put a call to your long running code in the run() method and start the thread and then exit back to Swing.
Re: GUI Lockup during run
Ok, so based on what I'm reading, in order to create a Thread, i need to send it a runable object, which would be the object that contains all my methods for what I am trying to do. But, due to this programing doing several different types of things and because each type of thing needs direct access to their own GUI objects, each class that contains the methods I need to run also contains their own JPanel and their components for that JPanel. So, by sending Thread the runable object, wont it also run the GUI in that Thread along with the methods? Which means that my problem will still exist.
Just for information purposes:
To give an idea of the scope of the program, it currently contains about 4 different processes with their own classes with about 1500 lines of code each (some of which are commented out for faster periodic testing); as well as 5 helper classes and 1 main class.
Re: GUI Lockup during run
Sounds like your coding got ahead of your design.
If you need to have Swing update the GUI while in a long running background task, use the SwingUtilities invoke... methods to call the Swing methods. They will keep your thread isolated from Swing's EDT.
Quote:
runable object, which would be the object that contains all my methods
Not quite. You could call the methods of other classes, vs having them be in the Runnable.
Re: GUI Lockup during run
Quote:
Not quite. You could call the methods of other classes, vs having them be in the Runnable.
Ok, so I found this works when I put it in the ButtonListener class:
Code java:
progressBar = new ProgressBar(10);
Runnable runnable = new Thread(){
public void run(){
//cleanSource();
writeMain();
System.out.println("Finished");
confirmArea.setText("Finished \n"+confirmArea.getText());
}
};
Thread thread = new Thread(runnable);
thread.start();
I dont know how pretty it is, but it does the job. Thanks for the help.