Stopping JProgressBar Undefined Mode in SwingWorker

I want to stop the progress bar indefinite mode as soon as mine doInBackground(the SwingWorker method) returns null(this means when my task will be completed). Here is my code inside the button; when I run my code, I get an error. Here is the code:

private void StartButtonMouseClicked(java.awt.event.MouseEvent evt) {                                         

final Main f22 = new Main();

initializer();

f22.getfile(FileName, 0);
f22.execute();

SwingUtilities.invokeLater(new Runnable() {

    @Override
    public void run() {
        jProgressBar1.setIndeterminate(true);
        try {
            if (f22.doInBackground() == null) {
                jProgressBar1.setIndeterminate(false);                        
            }
        } catch (IOException ex) {
            Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
});

Here is the error I get:

#
# A fatal error has been detected by the Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc = 0x6e1b0750, pid = 4988, tid = 5464
#
# JRE version: 7.0-b141
# Java VM: Java HotSpot (TM) Client VM (21.0-b11 mixed mode, sharing windows-x86              
# Problematic frame:
# V [jvm.dll + 0xa0750]
#
# Failed to write core dump. Minidumps are not enabled by default on client  

  versions of Windows
#
+3
1

, , SwingWorker. doInBackground() , - SwingWorker, SW. PropertyChangeListener SwingWorker , .

.

  final Main f22 = new Main();
  initializer();
  f22.getfile(FileName, 0);
  f22.addPropertyChangeListener(new PropertyChangeListener() {
     @Override
     public void propertyChange(PropertyChangeEvent pcEvt) {
        if (pcEvt.getNewValue().equals(SwingWorker.StateValue.DONE)) {
           // do your stuff here
        }
     }
  });
  f22.execute();
+5

All Articles