my dog learned polymorphism*
The moose likes Swing / AWT / SWT and the fly likes Table Model data not getting updated after JTable looses focus 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 "Table Model data not getting updated after JTable looses focus" Watch "Table Model data not getting updated after JTable looses focus" New topic
Author

Table Model data not getting updated after JTable looses focus

Sanjeev Debnath
Greenhorn

Joined: May 25, 2007
Posts: 16
Hi

I have a jtable, created a table model and a table cell editor.
The cell editor is JTextField. When I click on any cell, it turns to text field and I edit the contents.
When I click on another cell, the content of the text field reflected to the table model.
But when I click on any JButton outside the table after editing the text in the text field inside the cell,
the contents are not reflecting in the model.

In my table model setValue(), I called the fireTableDataChanged() method.

Please help me.
Sugantha Jeevankumar
Ranch Hand

Joined: Jun 06, 2007
Posts: 93
This can be achieved by calling cancelCellEditing() of the DefaultCellEditor, as soon as you know that the update on the table cell is over.


SCJP 5.0
Sanjeev Debnath
Greenhorn

Joined: May 25, 2007
Posts: 16
Hi Sugantha

Thank you for the reply.
But its not working. I tried your suggestion, but after entering value in textfield which is a cell,
I clicked on the button and the textfield/cell's content disappeared and returning to the same situation.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19722
    
  20

Try this:
It's one of the, unfortunately, hidden features in Swing.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Sanjeev Debnath
Greenhorn

Joined: May 25, 2007
Posts: 16
Hi Rob,

Thanks a lot!!!
You save my day.

It fixed my problem.

Thanks again....
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Table Model data not getting updated after JTable looses focus