Wait until end of thread execution before executing the next method

后端 未结 6 2073
慢半拍i
慢半拍i 2021-01-28 19:28

I\'ve a JFrame subclass that manage my UI and call a method of Item Object to import items in my DB:

public TestGUI() throws IOException
{

    initComponents();         


        
6条回答
  •  盖世英雄少女心
    2021-01-28 20:14

    What you can do is move the table.refresh(); code at the end of the child thread code and use SwingUtilities.InvokeLater to forward it to the GUI thread event queue:

     public void run() {
          //...
          SwingUtilities.InvokeLater(
                new Runnable() {
                     public void run() {
                         table.refresh();
                     }
                });         
     }
    

    That way you are executing it on the GUI thread but only when the child thread finished its work.

提交回复
热议问题