Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

The right model for this bound table?  RSS feed

 
Greg Pata
Ranch Hand
Posts: 31
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I would like to enlighten my knowledge of Table Model. In this program, the RightTable(RightModel) is updated as soon as the left table changes.
To do it, the solution I found is based on a TableModelListener and a TableModel where fireTableCellUpdated is used in the setValueAt method.
I think I was explained in this forum this is the wrong way...
The right way should be to used the setValueAt method of the TableModel. I tried it without success. So any idea on how to update the RightTable the right way?
Thank you for your help.

Here is the code:



 
m Korbel
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
- override setValueAt in AbstractTableModel instead of listening of event from TableModelListener (not designated for)

- overrride getColumnClass in AbstractTableModel instead of parsing from/to

- setValueAt should be contains super.setValueAt
 
Greg Pata
Ranch Hand
Posts: 31
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you m_Korbel. I will try this way. Given the details of your reply I am not sure I will come back with the answer you think.
 
Greg Pata
Ranch Hand
Posts: 31
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am stuck. How is setValueAt called?
Here is the code:


 
Greg Pata
Ranch Hand
Posts: 31
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The simpler the better.
Now I just need to find the right way to update the right table.
 
Greg Pata
Ranch Hand
Posts: 31
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Done! I just add "fireTableCellUpdated(rowIn, col);" at the beginning of the getValueAt method in the RightModel Class.
But it is updated before the real thing is done... Strange enough it seems to work!
Not sure this would be the recommended way. Anyone?
 
m Korbel
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
- fireTableCellUpdated should be exclusively inside setValueAt,

- getValueAt just to returns value for JTables view
 
Greg Pata
Ranch Hand
Posts: 31
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are right.

To sum up:
In this code I have 2 tables from class MyTable and RightTable.
The first table is externally updated every second. The rows of the second table should be updated when the rows of the first table are updated.

What I first did was: addTableModelListener to the TableModel of the first table and use e.getType() == TableModelEvent.UPDATE
To avoid using the addTableModelListener method, the solution I propose is to update the second table in the update(Observable,Object) method of the model of MyTable.
It works fine and I think this is the best solution so far. Or do you have any other ideas?

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!