wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes Problem with JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Problem with JTable" Watch "Problem with JTable" New topic
Author

Problem with JTable

Manan Pacholi
Greenhorn

Joined: Jul 10, 2011
Posts: 6

/*************************************************************************************************************/
Actually I'm trying to display the captured packet details in the JTable which follows DefaultTableModel. Now I encapsulate all the fields of the packet into a string and I try to add this string into my table as a new row. But no changes are reflected in my table. Also in the GUI once I hit the START button to start packet capture, my application goes dumb and stops responding! To find a reason for this problem, I added those print statements in between to see whether my code is running properly or it gets stuck somewhere. But the code is running properly, I can see the results of println statement on my screen, but the table is not updated and the application window freezes. Please someone help me with this. Thanks.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2180
    
    7
Please edit your posting and repost the code using the "Code" tags. Once the code is pasted you selected the code and then click the "Code" button.

> Also in the GUI once I hit the START button to start packet capture, my application goes dumb and stops responding!

This is because you are blocking the Event Dispatch Thread with your packet listener so the GUI never gets a chance to respond to events and repaint itself.

Read the section from the Swing tutorial on Concurrency for an explanation. You should be using a Swing Worker.
Manan Pacholi
Greenhorn

Joined: Jul 10, 2011
Posts: 6
sorry about the way in which I put my code first....but I've corrected it now......thanks for the reference to concurrency in swing....will definitely go through it....but what I'm really concerned about right now is why the table is not refreshed.....do you think that it is because of the thread problem that you mentioned? please help me out.....Thanks...
Manan Pacholi
Greenhorn

Joined: Jul 10, 2011
Posts: 6


Ok now I have used the SwingWorker thread for capturing packets, and so my application does not become 'DUMB' as it used to before.....but still my jtable stays blank still......! Please guys help me nail this problem......I am so very desperate......
Manan Pacholi
Greenhorn

Joined: Jul 10, 2011
Posts: 6
Come on guys......please help me...I'm stuck because of this little problem.....and it is driving me nuts!
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19684
    
  20

Even then, PatienceIsAVirtue.

Anyway, the problem is in the process method. You haven't overridden it, you've overloaded it. The method should be this:
You need to process all elements of the List, since SwingWorker may choose to buffer the published values and let you process more than one at a time.
Also, DefaultTableModel's insertRow method already fires the necessary events, so no need to manually fire any.

Oh, and you may want to move line 75 (the publishing) outside the if-statement. If eth_pkt.frametype==EthernetPacket.ETHERTYPE_ARP nothing will be published now.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2180
    
    7
Be Forthright When Cross Posting To Other Sites

I see you received and answer in your cross posting: http://stackoverflow.com/questions/6655141/java-swing-problem-updating-the-jtable.

So why haven't you responded to this posting indicating a solution has been found so people don't waste time answering questions that have already been answered. It amazes me how selfish people can be. First you complain because we don't respond fast enough. Then you don't post the answer when you find one.


Manan Pacholi
Greenhorn

Joined: Jul 10, 2011
Posts: 6
Sorry guys for not updating the status of this query.....I'll make sure it won't happen again.............but my problem with JTable has been solved....yes the problem was definitely in my process method....


Manan Pacholi
Greenhorn

Joined: Jul 10, 2011
Posts: 6
Manan Pacholi wrote:Sorry guys for not updating the status of this query.....I'll make sure it won't happen again.............my problem with JTable has been solved....yes the problem was definitely in my process method....


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with JTable