javax swing freezing
Author |
Message |
matt271
|
Posted: 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
|
|
|
|
|