aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes question about my JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "question about my JTable" Watch "question about my JTable" New topic
Author

question about my JTable

dennis deng
Ranch Hand

Joined: Nov 07, 2001
Posts: 42
hi, guys, a little question about my GUI, do someone know exactly ' fireTableCellUpdated(null) 'means? is it means update all table cells or do nothing? BTW, in my book flight method, i need to check db field: 'Available seats' and refresh JTable by method:fireTableCellUpdated(index, 8); you know this is not obey the expectation of future functionality enhancements such as database sturcture changed and 'Available seats 'become another position not 8 ? who can tell me something about this ? thanks alot.


Sun Certificated JAVA Programmer(SCJP)<br />Sun Certificated JAVA Developer(SCJD)<br />Sun Certified Web Component Developer(SCWCD)
Peter Crowley
Greenhorn

Joined: Nov 06, 2001
Posts: 14
Originally posted by dennis deng:
hi, guys, a little question about my GUI, do someone know exactly ' fireTableCellUpdated(null) 'means? is it means update all table cells or do nothing? BTW, in my book flight method, i need to check db field: 'Available seats' and refresh JTable by method:fireTableCellUpdated(index, 8); you know this is not obey the expectation of future functionality enhancements such as database sturcture changed and 'Available seats 'become another position not 8 ? who can tell me something about this ? thanks alot.

I think that you would want to decouple the table from the data. The JTable and TableModel classes are a good example of Model-View. A differnet way to solve this problem would be to add an outside class to do the work for you. This class (the controller in MVC pattern) should update the data and then the TableModel should fire a tableChanged() with a TableModelEvent that has the fine grained information of what specifically changed.
You do not have to account for the data columns changing, however. Nowhere does it even hint that this data structure (schema) will ever change.
I hope that this helps.
-Peter Crowley

[This message has been edited by Peter Crowley (edited November 27, 2001).]


-Peter Crowley,<BR>who is looking for work in North Florida
dennis deng
Ranch Hand

Joined: Nov 07, 2001
Posts: 42
Thanks Peter,
I think you are right about the database structure changing. Do you know 'fireTableCellUpdated(null) 'means? is it means update all table cells or do nothing? I read some sun doc but not found the answer. BTW, this method is used in my controller class. Thanks alot.
dennis
Originally posted by Peter Crowley:
I think that you would want to decouple the table from the data. The JTable and TableModel classes are a good example of Model-View.
[This message has been edited by Peter Crowley (edited November 27, 2001).][/B]

Trevor Dunn
Ranch Hand

Joined: Jun 13, 2001
Posts: 84
I would think you would get a compile time error if you used that. The signiture of the method in AbstractTableModel is fireTableCellUpdated(int row, int col). IF you want to update the whole the table use fireTableDataChanged();
Trevor
Peter Crowley
Greenhorn

Joined: Nov 06, 2001
Posts: 14
This is the method from the src.jar distributed in the JDK:

So, yes, this is exactly what I was saying. You are doing it correctly if you use this method.


As for what it does... This method sends a table model event to the listeners (namely the JTable) to let them know hat there was a change in the data. The TableModelEvent allows you to specify exactly what changed so that the JTable can update specific cells instead of updating the entire table every time that there is a change. It allows increased performance from the JTable.
-Peter Crowley
Martin Habicht
Greenhorn

Joined: Nov 07, 2001
Posts: 17
Hi,
if you want to program more generic and not depend on the actual column number, you can use findColumn("col name").
-Martin

see javadoc for details:
java.lang.String)" TARGET=_blank rel="nofollow">http://java.sun.com/j2se/1.3/docs/api/javax/swing/table/AbstractTableModel.html#findColumn(java.lang.String)
 
Don't get me started about those stupid light bulbs.
 
subject: question about my JTable
 
Similar Threads
NX: Update owner in JTable
update data in the JTable
JTable
Problems with JTable & JComboBox
JTable