aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes JTable: room record gets updated/booked by providing cell value, without book button Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "JTable: room record gets updated/booked by providing cell value, without book button" Watch "JTable: room record gets updated/booked by providing cell value, without book button" New topic
Author

JTable: room record gets updated/booked by providing cell value, without book button

Margarita Babkova
Ranch Hand

Joined: May 09, 2012
Posts: 32
Hi there,

I am working on user interface and I got a strange issue with the way my JTable works.

1. Let’s say I ran a normal search for all records and got expected results:
Palace Smallville 2 Y $150.00 2005/07/27
Castle Smallville 6 Y $220.00 2005/11/19 etc.

2. I select first row and type ownerId value 12345678 into column ownerID (isCellEditable=true for this row/column).
AND move focus from this cell, and put it back again on that cell.
3. Re-run the same search and somehow this owner id gets right into my hotel records, without using Book button or anything.
Palace Smallville 2 Y $150.00 2005/07/27 12345678
Castle Smallville 6 Y $220.00 2005/11/19

4.I could not even book the given room record, because it says that it is already booked – but I did nothing but typed ownerId.

I tried to discard changes with code lines below, but it did not help much.

if (table.getCellEditor() != null) {
table.getCellEditor().cancelCellEditing();
}

What am I doing wrong?

Thank you
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5596
    
  15

If you re-run the original search are you replacing the old table model (containing the 2 records) with a new one (containing the new search results)?

Another possibility: don't make your cells editable


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Margarita Babkova
Ranch Hand

Joined: May 09, 2012
Posts: 32
I commented out this isCellEditable method from my model, and Added one JTextField next to the Book button and able to book room this way.
Outstanding: the Owner column does not show its new value untill I re-run Search.
But I will work on it.
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5596
    
  15

Margarita Babkova wrote:Outstanding: the Owner column does not show its new value untill I re-run Search.

After booking I re-run the search automatically (programatically. That way the owner column shows the new value.
Margarita Babkova
Ranch Hand

Joined: May 09, 2012
Posts: 32
I did the same, but was not really sure that it was most efficient solution...

I tired to make it work with tbl.fireTableDataChanged() inside Book methof of a Controller class - but it did not work.
For now i will leave it as it is (with the call to the search inside book method), because it does work.

thank you very much
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JTable: room record gets updated/booked by providing cell value, without book button