aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes fireTableDataChanged () Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "fireTableDataChanged ()" Watch "fireTableDataChanged ()" New topic
Author

fireTableDataChanged ()

kamiya sei
Greenhorn

Joined: Dec 12, 2012
Posts: 25
The following is a small snippet of my code, I wonder method fireTableDataChanged () when I use it and are necessary when working with JTable ???

tbModel = new DefaultTableModel(data, header);
tbModel.fireTableDataChanged();
tblStudent.setModel(tbModel);
btnSearch.setEnabled(true);

Regards.
Kamiya Sei
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18657
    
    8

In that particular case, no, there is no point in calling "fireTableDataChanged" on a table model which has just been created and has had no changes yet.

There are times when you need to call it -- that's why the method exists, of course -- but that is not one of those times.
Nam Ha Minh
Ranch Hand

Joined: Oct 31, 2011
Posts: 498

I usually use fireTableDataChanged() after making some changes to the table model. Without that call, the table GUI doesn't get updated.


PM Me If You Want to get Urgent Help on Java Programming
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4642
    
    5

Nam Ha Minh wrote:I usually use fireTableDataChanged() after making some changes to the table model. Without that call, the table GUI doesn't get updated.


I guess you're talking about a custom (and possibly badly implemented) TableModel. The posted code shows a DefaultTableModel -- which takes care of firing changes without any outside assistance.

Moreover, as Paul said, no changes have been made to the data; additionally, the model is not associated with any JTable so in any case it won't have any listeners that might respond to fireTableDataChanged().


luck, db
There are no new questions, but there may be new answers.
Nam Ha Minh
Ranch Hand

Joined: Oct 31, 2011
Posts: 498

Darryl Burke wrote:

I guess you're talking about a custom (and possibly badly implemented) TableModel. The posted code shows a DefaultTableModel -- which takes care of firing changes without any outside assistance.

Moreover, as Paul said, no changes have been made to the data; additionally, the model is not associated with any JTable so in any case it won't have any listeners that might respond to fireTableDataChanged().


Sorry, my answer did not target to context of the OP's example. I meant using a custom table model which is associated with a table.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: fireTableDataChanged ()