I'm still building a program to test images. To update the GUI I made a swingworker and he works fine until I hit the magical number of 101 selected files.
I need to test several hundred images in one directory and don't want to sperate them to blocks of 101 images each. So has anyone an idea, why it stops working without activating the done method?
To make it more clearly:
testing Img 1, testing Img 2, ....testing Img X (x <=100), testing Img 101 stopping, no testing or done or error Img 102 (just dont progress) only message I could find out ist that the PropertyChangeEvent hits "DONE" after 101 tested images. But the property should still change and the progressBar shows 99% and the popUp shows 101/102. (Testing with numbers till 100 both work fine and show at the end 100% and 100/100 while my log gets the message "DONE"!
What I update with this worker, is a progressBar and a popUp with the current % (progressBar) and current image (e.g.101/110)
Here's the swingworker itself:
private void work(final File filex)
{
worker = new SwingWorker<Void, Integer>()
{
@Override
protected Void doInBackground() throws Exception
{
File file = filex;
if (file.isDirectory())
{
File[] listOfFiles = file.listFiles();
iMax=listOfFiles.length;
for (i= 0; i< iMax; i++)
{
aktionenTest(listOfFiles[i]); //processing/working here
setProgress(i);
}
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}
else
{
iMax = 1;
i = 1;
aktionenTest(file);
setProgress(i);
}
return null;
}
@Override
protected void process(List<Integer> chunks)
{
}
@Override
protected void done()
{
if(worker.isCancelled())
{
log.append("Cancelled!");
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}
else
{
log.append("DONE");
}
}
};
worker.addPropertyChangeListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent event) {
System.err.println(event);
log.append(""+event+newline);
if(event.getPropertyName().trim().equals("progress"))
{
if(event.getOldValue().equals(0))
{
popupCounter((Integer) event.getNewValue());
}
if(iMax == 1)
{
maxProg = iMax;
curProg = ((Integer) event.getNewValue())*100/maxProg;
progressBar.setValue(curProg);
popupUpdate((Integer) event.getNewValue());
}
else
{
maxProg = iMax;
curProg = (((Integer) event.getNewValue()+1))*100/maxProg;
progressBar.setValue(curProg);
popupUpdate((Integer) event.getNewValue());
}
}
}
});
worker.execute();
}
Here's the output of the PropertyEvent before 101
java.beans.PropertyChangeEvent[propertyName=progress; oldValue=99; newValue=100; propagationId=null; source=components.Bilderexplorer$4@79885c3a]
and after 101 (but there is still Img 102 left)
java.beans.PropertyChangeEvent[propertyName=state; oldValue=STARTED; newValue=DONE; propagationId=null; source=components.Bilderexplorer$4@79885c3a]
So has anyone an idea on what the problem is? Maybe I'm too codeblind from my own code to find it.
Greets and thanks
Zorian
When you call setProgress(i)
with i>100 it throws
new IllegalArgumentException("the value should be from 0 to 100");
You can replace it with something like setProgress(i*100/iMax)
The exception is never caught and just causes the thread to stop abnormally.