Ok. Alla fine ho fatto così e funziona
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.border.EmptyBorder;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.DefaultTableModel;
public class prove extends JFrame {
private JPanel contentPane;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
prove frame = new prove();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public prove() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 736, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setLayout(new BorderLayout(0, 0));
setContentPane(contentPane);
JTable table = new JTable();
table.setModel(new DefaultTableModel(
new Object[][] {
{new Double(1.82), "", ""},
},
new String[] {
"K fact", "Val", "Tot"
}
));
table.getModel().addTableModelListener(new TableModelListener() {
public void tableChanged(TableModelEvent e) {
int col = e.getColumn();
int row = e.getFirstRow();
if (col == 1) {
double val = Double.parseDouble((String) table.getValueAt(row, 1));
double tot = (double) table.getValueAt(row, 0) * val;
table.setValueAt(tot, row, 2);
}
}
});
contentPane.add(table, BorderLayout.CENTER);
}
}
E' giusto???
Grazie. Ciao.