0

here is my exemple of making a circular loading bar with Jlayer but now the layer start and stop after the execution of the btnLoad.addActionListener() and stop after a while of determinated timer (4000) so my problem that I need it to start when I click the button load and stop after complete the loading of the file !!!

  final WaitLayerUI layerUI = new WaitLayerUI();

       jlayer = new JLayer<JPanel>(this, layerUI);

        final Timer stopper = new Timer(4000,new ActionListener() {
              public void actionPerformed(ActionEvent ae) {
                layerUI.stop();
              }
            });
            stopper.setRepeats(false);
          if (!stopper.isRunning()) {
            stopper.start();
          }
        btnLoad.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
              layerUI.start();
              DataManager dataManager = new DataManager();
              try {
        dataManager.loadFromFile("C:/Users/*****PC/Downloads/****.csv");
            } catch (Exception e) {

                e.printStackTrace();
            }
            }
          }
        );
tios646
  • 5
  • 4
  • to ignore answer here, is wrong, Swing Timer is proper way, I'm sure that animation with Jlayer is there a few times, btw this is MadProgrammer's area – mKorbel Mar 25 '14 at 21:15
  • @MadProgrammer I'm still think that this is your area – mKorbel Mar 26 '14 at 10:04

1 Answers1

0

You should load the file on another Thread and not the Event Dispatch Thread. Assuming your loadFromFile method blocks until it loads the file, you can then hide the layer, but you must hide on the Event Dispatch Thread and not the new Thread you started for loading the file.

Remove your timer and replace your try block with this:

    try {
        new Thread(new Runnable(){
            public void run() {
                dataManager.loadFromFile("C:/Users/*****PC/Downloads/****.csv");
                EventQueue.invokeLater(new Runnable(){
                    public void run() {
                        layerUI.stop();
                    }
                });
            }
        }).start();
    } catch (Exception e) {
        e.printStackTrace();
    }
Charlie
  • 8,530
  • 2
  • 55
  • 53