Intanto, invio il codice della classe che ho pensato mi serve per far partire l'altro thread.
Ma sicuramente ho scritto qualcosa di intutile perchè si vede che nn c'è alcun collegamento tra il task e quello che mi serve a me.....codice:public class ProgressBar_JFrame extends javax.swing.JFrame { UserProfile userL = Persistence.getCurrentUserProfile(); ContactsManager contactsManager = new ContactsManager(userL); ArrayList<Contact> contatti = new ArrayList(); SimpleTableModel tableModel = null; /** Creates new form ProgressBar_JFrame */ public ProgressBar_JFrame() { initComponents(); progressBar.setMinimum(0); progressBar.setMaximum(100); progressBar.setValue(0); updateContactsJTable(); progressBar.setValue(100); //Call setStringPainted now so that the progress bar height //stays the same whether or not the string is shown. progressBar.setStringPainted(true); task = new Task(); task.execute(); } /** * Invoked when task's progress property changes. */ public void propertyChange(PropertyChangeEvent evt) { if ("progress" == evt.getPropertyName()) { int progress = (Integer) evt.getNewValue(); progressBar.setIndeterminate(false); progressBar.setValue(progress); // taskOutput.append(String.format( // "Completed %d%% of task.\n", progress)); } } /* * richiama il metodo che provvede a scaricare la lista aggiornata */ public boolean updateContactsJTable(){ try { contactsManager.update(); return true; } catch (WebServiceException ex) { ex.printStackTrace(); } catch (ConnectException ex) { ex.printStackTrace(); } return false; } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { ... }// </editor-fold> private Task task; class Task extends SwingWorker<Void, Void> { /* * Main task. Executed in background thread. */ @Override public Void doInBackground() { Random random = new Random(); int progress = 0; //Initialize progress property. setProgress(0); //Sleep for at least one second to simulate "startup". try { Thread.sleep(1000 + random.nextInt(2000)); } catch (InterruptedException ignore) {} while (progress < 100) { //Sleep for up to one second. try { Thread.sleep(random.nextInt(1000)); } catch (InterruptedException ignore) {} //Make random progress. progress += random.nextInt(10); setProgress(Math.min(progress, 100)); } return null; } /* * Executed in event dispatch thread */ @Override public void done() { Toolkit.getDefaultToolkit().beep(); } } /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new ProgressBar_JFrame().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JPanel jPanel1; private javax.swing.JProgressBar progressBar; // End of variables declaration }

Rispondi quotando