0

I am populating a JTable with an ArrayList that contains necessary packet data. My JTable populates after all of the packets are received rather than one by one. I am using the Jnetpcap library and I believe I am having a thread issue.

I have implemented a Swing Worker in my Capture Class but I was wondering where to put the doInBackground() effectively. I read up on concurrency so I am thinking it's the issue here, my syntax is off. Do I need a Table Model and if so, where to implement?

EDIT: public class Capture extends SwingWorker {

//Variables

protected doInBackground() throws Exception {
 //Get Packets
 //Convert data to ArrayList 
pulish(list);
PCap.loop(10, jPacketHandler, null);
PCap.close();

So basically the loop will get 10 packets but the Table only updates once the packets are received in PCap.close(); I know my Swing is being blocked somehow but I am not sure where.

My GUI class calls this method explicitly (doInBackground)

  • 1
    It will really help if you show show come, preferable a [mcve] – tddmonkey Jun 28 '16 at 17:55
  • 1
    `pulish(list);` - well you are publishing the entire list at one time so of cource the JTable is only going to be updated once. If you want each row to be displayed one at a time then you need to get one row of data from your PCAP and publish that row. The problem is with your PCAP code, not Swing. – camickr Jun 28 '16 at 18:10
  • Well the list is updated constantly, I see the ArrayList growing with printout statements. I need Swing to keep checking for an increase in the list. – esmith08734 Jun 28 '16 at 18:28
  • According to your comment, you are building the ArrayList, so you would publish the ArrayList and then clear the data in the ArrayList so you can add more data. Swing has no idea where the data comes from. It us up to you to only publish new data as it is received. – camickr Jun 28 '16 at 18:33
  • It seems like publish is not effecting the row data being printed. I have taken it out and it's the same effect. My rows are created in my GUI Class. final Object[][] row = new Object[list.size() / columnNames.length][columnNames.length] – esmith08734 Jun 28 '16 at 18:54
  • @esmith08734, Well you also need to implement the `process(...)` method to add the data in the List to the TableModel. Read the section from the Swing tutorial on [Tasks That Have Intermediate Results](http://docs.oracle.com/javase/tutorial/uiswing/concurrency/interim.html) for more information and a working example. – camickr Jun 28 '16 at 20:06
  • Something like protected void process(List list) { for (int i = 0; i < list.size(); i ++) { list.get(i); } – esmith08734 Jun 28 '16 at 21:39

0 Answers0