title: How to refresh a JTable from another Frame as a button is pressed?
body: <p><a href="https://stackoverflow.com/questions/9785560/java-how-to-refresh-jtable-in-one-frame-from-another-frame">Java, How to refresh JTable in one frame from another frame</a></p>
  
  <p><a href="https://stackoverflow.com/questions/23488314/how-to-refresh-a-jtable-after-database-operations-without-frame-reload">How to refresh a JTable after database operations without frame reload?</a></p>
  
  <p>I am aware that very similar questions have been asked. However none of the answers provided solved my problem.</p>
  
  <p>So i have an application in Java that handles interaction with several databases. Within the program you can add a record, change the criteria for what is to be displayed in the Jtable and edit records that already exists(For example changing the name of a client).</p>
  
  <p><img src="https://i.stack.imgur.com/ZtOnp.jpg" alt="Screen shot of my program"></p>
  
  <p>When i click on the "Ascending" checkbox it reverses the rows just as it is supposed to do.</p>
  
  <p><img src="https://i.stack.imgur.com/8vfOj.jpg" alt="It now orders by ASC not DESC as previously."></p>
  
  <p>So here the JTable is updated as i press on a checkbox or any of the other buttons shown.</p>
  
  <p>When you press on a row, Another frame containing more information on the row shows up. Where you are supposed to be able to edit the name/set as finished and so forth. And this works because when i check the database i see that that
  changes i made have been applied. Likewise if i click on the refresh button.</p>
  
  <p><img src="https://i.stack.imgur.com/tZWIo.jpg" alt="The external frame that is summoned so you can edit the row"></p>
  
  <p>However when i press on "Finished/edit" the JTable will not update at all until i manually do something(like pressing the refresh button).</p>
  
  <p>Here is the code used in the external JFrame.</p>
  
  <pre><code>    private void AlterTransactionMousePressed(java.awt.event.MouseEvent evt) {                                              
      EditTransaction();
  
  }
  
  
  private void EditTransaction(){
       GUImannager.RefreshServTable();
  }
  
  //In the GUImannager class
  
      public static void RefreshServTable(){
      System.out.println("RefreshServTable Method has been summoned.\n");
      MainGUI.TableRefresher();
      //The MainGUI is a static variable which contains the JFrame object of the main frame that is summoned that contains the core of the programs such as the pictures as i used.
  }
  </code></pre>
  
  <p>The TableRefresher method is the exactly same method that is used when clicking the refresh button. What it does is start a thread where this code is summoned.</p>
  
  <pre><code>//Gets the data from the database based on conditions.
                  TableModel model = new DefaultTableModel(TransData, Colnombs);
              ServiceTable.setModel(model);
              ServiceTable.revalidate();
              ServiceTable.repaint();
              TableContainer.setViewportView(ServiceTable);
  </code></pre>
  
  <p>And this code ussually works. But whenever it is summoned from an external source it does not work at all. It prints out text stating it has been summoned but it does not refresh the table when summoned externally, only when summoned by something in the same JFrame such as the "refresh" button will it work.</p>
  
  <p>I have tried having code that "listnens" to changes and then updates but while this was apparently summoned according to the system out put it did not effect the program in the way i wanted.       </p>
  
  <p>The second JFrame is in another class, but even when i had it as a subclass or within the same file it still didn't work, so i suspect the problem has to do with handling more than one JFrame.</p>
  
  <p>I know this is a very complicated questions, and although almost identical questions have been asked they did not contain any answer that worked for me.</p>
  
  <p>The data is retrieved manually and thus the table is not "bound" to any database(This is because i switch between a SQLite source and a MySQL source).</p>
  
  <p>If any more information/code is necessary i will happily provide it, Any attempts to solve this problem will be very appreciated. If this was an easy question I am sorry as i have not gotten that much experience in software programming yet.</p>
  
  <p>Sincerly...</p>
  
  <p>//Orville Nordström.</p>