0

I am currently trying to implement threading on a table. Unfortunately, this table does not show values concurrently when I am adding values by query to the table manually. Here's the event that I have performed:

private void formWindowOpened(java.awt.event.WindowEvent evt) {    
  Runnable hello = new orderRun(tableOrder); //sending the table to the class
  Thread thread1 = new Thread(hello); //opening a thread
  thread1.setDaemon(true);
  thread1.start();
}    

and here's a class that is dedicated for it.

public class orderRun implements Runnable {

JTable t;

public orderRun(JTable t){
    this.t = t;
}

public void run(){
    String[] col = {"Invoice", "Customer", "Item", "Quantity", "Date Purchased"};
            DefaultTableModel tableModel = new DefaultTableModel(col, 0);

            t.setModel(tableModel);

            for (int i = 0; i < showOrders(LoginForm_CPOS.username).size(); i++)
            {
                tableModel.addRow(showOrders(LoginForm_CPOS.username).get(i).getItem().toArray());
            }
}

}

Now, is there anyway for the values on the table that is caught from the database to be shown concurrently or simultaneously when I add values by queries?

  • See [Concurrency in Swing](http://docs.oracle.com/javase/tutorial/uiswing/concurrency/) for reasons why this is a dbad idea, then see [Worker Threads and SwingWorker](http://docs.oracle.com/javase/tutorial/uiswing/concurrency/worker.html) for the most common solution – MadProgrammer Jun 17 '17 at 06:35
  • Without a runnable example, is difficult to be 100% sure of the exact cause of your problem, how ever, I'd make sure the table you think you're updating is actually the table on the screen – MadProgrammer Jun 17 '17 at 06:38

0 Answers0