I am adding objects from one JTable to another, and I can see through debugging that in the CustomTableModel the objects are being added to the list of objects. Only the first object I add shows up in the new JTable.
So I can add many objects to the TableModel, but only the first one is showing up in the JTable.
here's my add method:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
// TODO add your handling code here:
if(physPackageModel != null){
int h = secRowSeat2.getSelectedRow();
Physical_Package pp = PpackageList.get(h);
if(physPackageModel2 != null){
physPackageModel2.addRow(pp);
physPackageModel.removeRow(h);
}
else{
physPackageModel2 = new tableModel2();
physPackageModel2.addRow(pp);
physPackageModel.removeRow(h);
}
secRowSeat1.setModel(physPackageModel2);
}
else{
int h = secRowSeat2.getSelectedRow();
EventSeat es = eventSeatList.get(h);
if(eventSeatModel2 != null){
eventSeatModel2.addRow(es);
eventSeatModel.removeRow(h);
}else{
eventSeatModel2 = new EventTableModel2();
eventSeatModel2.addRow(es);
eventSeatModel.removeRow(h);
}
secRowSeat1.setModel(eventSeatModel2);
secRowSeat2.setModel(eventSeatModel);
repaint();
}
}
Let me know if you want to see my custom table model's.....
add and remove methods from customTableModel:
public void addRow(Physical_Package rowData)
{
insertRow(getRowCount(), rowData);
}
public void insertRow(int row, Physical_Package rowData)
{
modelData.add(row-1, rowData);
fireTableRowsInserted(row, row);
this.fireTableDataChanged();
}
public void removeRow(int row)
{
modelData.remove(row);
fireTableRowsDeleted(row, row);
}
public void insertRow(int row, Physical_Package rowData)
{
modelData.add(row-1, rowData);
fireTableRowsInserted(row, row);
this.fireTableDataChanged();
}
So much for copying the code from the working TableModel I gave you yesterday. That is not the code I gave you.
I don't see why you need any check for the existence of a table model. You should always create and display a table with a table model, even if the table contains no rows.