我正在做一个发票系统,当我修改金额列时,我需要自动更新总计(就像在 excel 中当你在 c1 中写 =a1*b1 时一样)在附图中我显示了表格并输入了 3 个条目,第一个第二个是数量 1 和 3,我导入价格和总列我通过第三个条目中的代码来完成我修改了数量,但总列中没有反映任何变化
添加按钮代码附加
DefaultTableModel modelo = new DefaultTableModel();
public frm_facturacion() {
initComponents();
cargar_jcombos();
modelo.setColumnIdentifiers(new Object[]{"CODIGO", "DESCRIPCIÓN", "CANTIDAD", "PRECIO", "TOTAL"});
}
private void btn_agregar_cod_barrasActionPerformed(java.awt.event.ActionEvent evt) {
if (jbox_cod_barras.getSelectedIndex() == 0) {
JOptionPane.showMessageDialog(this, "Ingrese un numero de cedula");
} else {
int id = jbox_cod_barras.getItemAt(jbox_cod_barras.getSelectedIndex()).getId();
ResultSet rs = DB_consultas_R_D.getTabla("select codigo_barras,descripcion,precio_venta from productos where id =" + id);
try {
while (rs.next()) {
modelo.addRow(new Object[]{rs.getString("codigo_barras"), rs.getString("descripcion"), txt_cantidad.getText(), rs.getString("precio_venta"),
(Integer.parseInt(txt_cantidad.getText()) * rs.getDouble("precio_venta"))});
}
rs.close();
jtabla_Ventas.setModel(modelo);
} catch (SQLException ex) {
Logger.getLogger(frm_clientes.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
谢谢
一段时间后,我找到了一个很好的解决方案。
这是结果 也接受小数