Skip to main content

TableModelListener problem

Please note these forums are being decommissioned and use the new and improved forums at
No replies
Joined: 2010-11-15

Hello everyone,

three days I'm crazy to make a JTable editable cells can change ... but I do not understand why the program uses my InteractiveTableModelListener but use another that I do not know what ... then you edit the table cell but I can not check the entered data to save so everything is temporary.HELP ME

import gestionesicurint.Mymodel.MyModelOperatori;
import gestionesicurint.Operatori;
import gestionesicurint.Server.Server;
import gestionesicurint.Server.Server_OP;
import gestionesicurint.Stampa;
import java.util.Vector;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.TableModel;

public class TableOperatori extends javax.swing.JFrame {

protected Server_OP server;
protected Server [] x;
protected MyModelOperatori dataModel;
protected MyModelOperatori ciccio;
protected Vector v;

public TableOperatori(Server [] array) {
public void initComponent() {

v= new Vector(server.GetArrayOp().length);
for(int i=1;i<server.GetArrayOp().length;i++)

dataModel = new MyModelOperatori(v);
dataModel.addTableModelListener (new InteractiveTableModelListener());

public class InteractiveTableModelListener implements TableModelListener {
public void tableChanged(TableModelEvent evt) {
if (evt.getType() == TableModelEvent.UPDATE) {
int column = evt.getColumn();
int row = evt.getFirstRow();
System.out.println("row: " + row + " column: " + column);//here it must print anything but don't work
jTable1.getModel().setValueAt(3, row, column);


this is my Table model

package gestionesicurint.Mymodel;

import gestionesicurint.GestioneOperatori;
import java.util.Vector;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableModel;

public class MyModelOperatori extends AbstractTableModel {

String[] ColName = {"Nome","Cognome","Codice Operatore","Data di Nascita","Costo Diurno","Costo Notturno","Costo Festivo"};
Vector v = null;
protected TableModel model;

public MyModelOperatori(Vector v)

public int getColumnCount(){
return ColName.length;
public int getRowCount(){
return v.size();
public Object getValueAt(int row,int col){
GestioneOperatori b = (GestioneOperatori)v.elementAt(row);
String val = null;
// la stringa corrispondente alla colonna
switch (col){
case 0: val = b.GetArrayDati()[0]; break;
case 1: val = b.GetArrayDati()[1]; break;
case 2: val = b.GetArrayDati()[2]; break;
case 3: val = b.GetArrayDati()[3]; break;
case 4: val = ""+b.GetArrayCosti()[0]; break;
case 5: val = ""+b.GetArrayCosti()[1]; break;
case 6: val = ""+b.GetArrayCosti()[2]; break;
default: val = "";
return val;

public String getColumnName(int columnIndex)
return ColName[columnIndex];
public boolean isCellEditable(int row,int col){
return true;

public void setValueAt(Object aValue, int aRow, int aColumn) {
GestioneOperatori b = (GestioneOperatori)v.elementAt(aRow);
String val = null;
// la stringa corrispondente alla colonna
switch (aColumn){
case 0: b.GetArrayDati()[0]=(String)aValue; break;
case 1: b.GetArrayDati()[1]=(String)aValue; break;
case 2: b.GetArrayDati()[2]=(String)aValue; break;
case 3: b.GetArrayDati()[3]=(String)aValue; break;
case 4: b.GetArrayCosti()[0]=Double.parseDouble((String)aValue); break;
case 5: b.GetArrayCosti()[1]=Double.parseDouble((String)aValue); break;
case 6: b.GetArrayCosti()[2]=Double.parseDouble((String)aValue); break;
default: val = "";


public String[] getColumnameArray()
return ColName;