• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Table Cell retains edited value

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have a JTable in which one column is editable. I created a DefaultCellEditor and did column.setCellEditor().
I also have a ComboBox. When this combobox is changed, I fetch new values from the DB and repopulate the JTable.
For editing any column in the JTable, I have to double click on that column and edit. When I edit and change the combobox, new rows are populated in but the last edited cell retains the value I entered before changing the combo box. Any idea how to stop this from happening?
Also, I have a JText field. The value I enter in this text field has to replicated for a column for all rows in the JTable. I have coded a document listener for the textfield and am using setValueAt() for each row of the JTable to copy this value. It is working fine. But again, just as in above problem, if any column is just Edited and I change the value of JText field, new value is copied for all the rows except for the previously edited cell. Any idea to fix this will be a great help.
thank you,
rambo
---------
here is how I popluate the JTable
AdjustmentOrderDetail orderDetail;
if (orderDetailList.size() > 0) {
Iterator it = orderDetailList.iterator();
int testCount = 0;
while (it.hasNext()) {
orderDetail = (AdjustmentOrderDetail) it.next();
Object[] job =
{
orderDetail.getUsocID(),
orderDetail.getOfficeID(),
orderDetail.getLastName(),
orderDetail.getFirstName(),
orderDetail.getOriginalPasscode(),
orderDetail.getSalesCode(),
orderDetail.getTransactionPasscode(),
orderDetail.getCorrectedPasscode()};
int count = dtm.getRowCount();
dtm.addRow(job);
}
}
--------------------
here is how I defined the tablecolumn
POSTTextField localTextField = new POSTTextField();
DefaultCellEditor localCellEditor = new DefaultCellEditor(localTextField);
correctedPasscodeColumn = new javax.swing.table.TableColumn();
correctedPasscodeColumn.setModelIndex(7);
correctedPasscodeColumn.setCellRenderer(localCellRenderer);
correctedPasscodeColumn.setCellEditor(localCellEditor);
-----------------------------------------
here is how I copy the textfiled value to a column in the table (for all rows)
POSTTable detailTable = (POSTTable) getControler().getControler(1);
for (int i = 0; i < detailTable.getRowCount(); i++) {
detailTable.setValueAt(correctedPasscode, i, 7);
}
 
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
jtable.getCellEditor().stopCellEditing() This will force the cell from editing mode so the value will be available.
 
and POOF! You're gone! But look, this tiny ad is still here:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic