1
I’m trying to get a 2-field multiplication on Jtable but I can’t do it
Specifically the Quantity Field and Unit Value to multiply and give the Total Value
Tela do Jtable
package Telas;
import Classes.Cliente;
import Classes.Material;
import Classes.Orcamento;
import Classes.Pedido;
import Hibernate.HibernateUtil;
import java.util.Iterator;
import java.util.List;
import javax.swing.table.DefaultTableModel;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
public class Tela_IncluirOrcamento extends javax.swing.JInternalFrame {
public Tela_IncluirOrcamento() {
initComponents();
Btn_Pagamento.setEnabled(false);
Btn_Total.setEnabled(false);
SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
Session session = sessionFactory.openSession();
List<Pedido> pedidos = session.createQuery("SELECT p FROM Pedido p JOIN FETCH p.clienteID_Cliente").list();
for (Pedido pedido : pedidos) {
Cliente cliente = pedido.getClienteID_Cliente();
DefaultTableModel model = (DefaultTableModel) TBL_Orcamento.getModel();
model.addRow(new Object[]{
cliente.getNome(),
pedido.getTipo_Servico()
});
}
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
Btn_Pagamento = new javax.swing.JButton();
Btn_Valor = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
TBL_Orcamento = new javax.swing.JTable();
Btn_Total = new javax.swing.JButton();
setClosable(true);
Btn_Pagamento.setText("LiberarPagamento");
Btn_Pagamento.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
Btn_PagamentoActionPerformed(evt);
}
});
Btn_Valor.setText("CalcularValorTotal");
Btn_Valor.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
Btn_ValorActionPerformed(evt);
}
});
TBL_Orcamento.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
},
new String [] {
"Nome do Cliente", "Tipo de Serviço", "Descricao do produto", "Quantidade", "Valor unitario", "Valor total", "Valor Total do Orcamento"
}
) {
boolean[] canEdit = new boolean [] {
false, false, true, true, true, false, false
};
public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit [columnIndex];
}
});
jScrollPane1.setViewportView(TBL_Orcamento);
Btn_Total.setText("CalcularTotalOrcamento");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1)
.addGroup(layout.createSequentialGroup()
.addGap(627, 627, 627)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(Btn_Pagamento, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(Btn_Valor, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGap(18, 18, 18)
.addComponent(Btn_Total)
.addContainerGap(115, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(Btn_Pagamento)
.addComponent(Btn_Total))
.addGap(18, 18, 18)
.addComponent(Btn_Valor)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
);
pack();
}// </editor-fold>
private void Btn_PagamentoActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void Btn_ValorActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
//Codigo Aqui
}
// Variables declaration - do not modify
private javax.swing.JButton Btn_Pagamento;
private javax.swing.JButton Btn_Total;
private javax.swing.JButton Btn_Valor;
private javax.swing.JTable TBL_Orcamento;
private javax.swing.JScrollPane jScrollPane1;
// End of variables declaration
}
Should the field already load with this account or only after some action? It would be interesting to add a [mcve] from your table, I couldn’t execute this code.
– user28595
the 2 fields first already load a query to make a Join of dps tables in the button "Release payment",the code goes in Btn_valor la below
– user63891
I just want code on Jtable to do the multiplication so you can disregard it up there
– user63891
Got it, can you add one [mcve] of your table with some of the data it will be?
– user28595
Code Ready ? updated image
– user63891