Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

question about my JTable

 
dennis deng
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Peter Crowley
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).]
 
dennis deng
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic