ProgressMonitorInputStream never pops up
I've been banging my head against a wall for almost 3 hours now, trying to get a progress monitor to open up while I load a big file. Here is my code:
Code :
public static void main(String[] args) {
AttTest testit = new AttTest();
testit.runAttTest();
}
public void runAttTest() {
String fname = "C:/test.model";
Vector<Object> test = new Vector<Object>();
try {
ObjectInputStream input =
new ObjectInputStream
(new ProgressMonitorInputStream(null, "Loading",
new FileInputStream(fname)));
while (true) {
test.add(input.readObject());
}
input.close();
} catch (Exception ex) {
System.err.println("Deserialization failed: " + ex.getMessage());
ex.printStackTrace();
}
}
The file is big - takes over 5 minutes to load. It loads fine, but the progress monitor never pops up. Can anyone tell me what I'm doing wrong here? Thanks for the help!
Best regards,
Michael
Re: ProgressMonitorInputStream never pops up
Maybe all that headbanging knocked something loose yesterday. Anyway, the code DOES work - just not when you're running in Debug mode (I'm using Netbeans). Running normally, the window pops up. It's blank, but at least it pops up. If anyone has any suggestions on why it's blank, I'd love to hear them...
Thanks.
Michael
Re: ProgressMonitorInputStream never pops up
I've never used ProgressMonitorInputStream, but usually when working with long tasks and showing updates in a GUI during that task, the long tasks should be performed in a separate thread and updates to the GUI called onto the GUI thread. See:
Lesson: Concurrency in Swing (The Java™ Tutorials > Creating a GUI With JFC/Swing)