Am I updating Swing component outside of EDT? Am I updating Swing component outside of EDT? multithreading multithreading

Am I updating Swing component outside of EDT?


You're really close...

Try something like this instead.

SwingWorker worker=new SwingWorker(){    protected Object doInBackground()    {        try{            Thread.sleep(3000);        }catch (InterruptedException ex){}        return null;    }    // This is executed within the context of the EDT AFTER the worker has completed...        public void done() {        jLabel1.setText(jLabel1.getText()+".");    }};worker.execute();

You can check to see if you're running in the EDT through the use of EventQueue.isDispatchingThread()

Updated

You could also use a javax.swing.Timer which might be easier...

Timer timer = new Timer(3000, new ActionListener() {    public void actionPerformed(ActionEvent evt) {        jLabel1.setText(jLabel1.getText()+".");    }});timer.setRepeats(false);timer.start();