Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 javax swing freezing
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
matt271




PostPosted: Tue May 12, 2009 7:24 pm   Post subject: javax swing freezing

swing keeps freezing on me

i have code like:
Java:
public boolean sendFile(File file, JProgressBar bar) {
        try {
            FileInputStream fstream = new FileInputStream(file);

            int sum = 0;
            bar.setMaximum((int)file.length());

            int read;
            byte[] bytes = new byte[BUFFER];

            while ( (read = fstream.read(bytes)) > 0 ) {
                ostream.write(bytes, 0, read);
                if (autoflush) ostream.flush();

                sum += read;
                bar.setValue(sum);
                bar.repaint();
            }

            fstream.close();
...


but it will not update the prog bar until its done. also while its loading, the gui is frozen.

i tried things like Thread.sleep(1); it didnt work.

in VB i would just say DoEvenets but i dont think java works like that.

also i tried running this in another thread. like i create a new thread then call my method. it still freezes

there has to be a way to make this not freeze, any help plz?
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 1 Posts ]
Jump to:   


Style:  
Search: