Reputation: 7458
In the code below I want to do something after invokeLater is done. 1) I can not use invokeAndWait due to setModel being called by dispatcher. 2) I can not change the value of a final variable inside thread! then how can I wait for involeLater to be done first?
boolean isDone=false;
SwingUtilities.invokeLater(new Runnable(){public void run(){
setModel(new DefaultTableModel(oRecordTable, sIP_TABLE_COL_NAMES_LIST));
isDone = true; // CAN NOT BE CHANGED HERE, AS HAS TO BE FINAL
}});
while (!idDone){
//wait
}
// do something here after the invokeLater is done
Upvotes: 0
Views: 648
Reputation: 3446
You could do that using a CountDownLatch. BUT this will be exactly the same as using invokeAndWait(), blocking the current Thread, so it does not make any sense.
correct:
SwingUtilities.invokeLater(new Runnable(){public void run(){
setModel(new DefaultTableModel(oRecordTable, sIP_TABLE_COL_NAMES_LIST));
isDone = true; // CAN NOT BE CHANGED HERE, AS HAS TO BE FINAL
// do something here after the invokeLater is done <=====
}});
CountDownLatch (useless, see above)
final CountDownLatch latch = new CountDownLatch(1);
SwingUtilities.invokeLater(new Runnable(){public void run(){
setModel(new DefaultTableModel(oRecordTable, sIP_TABLE_COL_NAMES_LIST));
isDone = true; // CAN NOT BE CHANGED HERE, AS HAS TO BE FINAL
latch.countDown();
}});
latch.await(); // could use invokeAndWait as well if blocking thread here ..
Upvotes: 1