0
I have a Jtable in my Mainform that receives data from a form in another window only after receiving the data Jtable does not update.
private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {
Connection conn = null;
PreparedStatement psm = null;
String cod = txtCod.getText();
String sql = "SELECT * FROM produtos WHERE cod = "+cod;
String nome = null;
float valor = 0;
String desc = null;
try{
conn = DatabaseConnection.MysqlConnection();
psm = conn.prepareStatement(sql);
psm.execute();
ResultSet result = psm.executeQuery(sql);
while(result.next()){
nome = result.getString("nome");
valor = result.getFloat("valor_m2");
desc = result.getString("descricao");
}
if(txtHeight.getText().equals("") && txtWidth.getText().equals("")){
float a2 = Float.parseFloat(JOptionPane.showInputDialog(rootPane, "Por favor insira a área da peça", "Área", HEIGHT));
float valorm = a2 * valor;
MainForm mf = new MainForm();
mf.addInTable(cod, nome, a2, valor, valorm);
this.setVisible(false);
psm.close();
conn.close();
}
else{
float alt = Float.parseFloat(txtHeight.getText());
float lag = Float.parseFloat(txtWidth.getText());
float area = alt * lag;
float valorm = area * valor;
MainForm mf = new MainForm();
mf.addInTable(cod, nome, area, valor, valorm);
this.setVisible(false);
psm.close();
conn.close();
}
}
catch(Exception ex){
System.out.println(ex);;
}
Here he will create the survey and send it to Jtable on Mainform
public void addInTable(String cod, String prod, float area, float prec, float precTot){
String nom = prod;
String con = cod;
String are = Float.toString(area);
String pre = Float.toString(prec);
String tot = Float.toString(precTot);
DefaultTableModel model = (DefaultTableModel) tblMain.getModel();
model.addRow(new Object[]{con, nom, are, pre, tot});
float total = 0;
total = total + precTot;
lblTrue.setText(Float.toString(total));
And here he adds the data to Jtable. Only how I said it doesn’t update the table and doesn’t show the data.
the problem is not popular the table and yes add in the table my friend pointed me the same fact mainForm create a new instance. But I’ve already arranged it, but thank you so much for your help.
– Asfhen