I can’t set in textField JAVA

Asked

Viewed 64 times

0

I have this frame, where clicking the 'SEARCH PRODUCT' button opens another frame with the list of registered products:

public class GeracaoOcamento extends javax.swing.JFrame {

     public GeracaoOcamento() {
        initComponents();
        setLocationRelativeTo(null);
    }

    public void retornaID(ListaProdutos frameProdutos, int idSelecionado) {
        ProdutoDAO pd = new ProdutoDAO();
        Produto produto = pd.buscarPorId(Produto.class, idSelecionado);

        lblNomeProduto.setText(produto.getNome());
        lblNumero.setText("2018/");
        System.out.println(produto.getNome());

    }

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        new ListaClientes().setVisible(true);
    }                                        


    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                        

        new ListaProdutos().setVisible(true);        

    }                                       


}

This frame has a product table. By double clicking on a line, I recover the product id of the clicked line and return this id to the previous frame. follow the code:

public class ListaProdutos extends javax.swing.JFrame {

    /**
     * Creates new form ListaClientes
     */
    public ProdutoTableModel tableModel;
    ProdutoDAO produtodao = new ProdutoDAO();
    GeracaoOcamento geracaoOrcamento = new GeracaoOcamento();

    public ListaProdutos() {
        initComponents();
        setLocationRelativeTo(null);

        tableModel = new ProdutoTableModel(produtodao.consultarTodos());

        tableLista.setModel(tableModel);
    }


    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        CadastroProduto cp = new CadastroProduto();
        //DeskPane.add(cp);
        cp.setVisible(true);

        this.setVisible(false);

    }                           

    private void tableListaMouseClicked(java.awt.event.MouseEvent evt) {                                        

        if (evt.getClickCount() == 2) {
            int linha = tableLista.getSelectedRow();
            int idSelecionado = (int) tableModel.getValueAt(linha, 0);
            geracaoOrcamento.retornaID(this, idSelecionado);
            this.dispose();
    }                                       
    }


}

In the return method of the Generation Class ID, I use the return data and search the database for the equivalent product.

I take the information of this product and try to set in a Textfield.

the problem is that no arrow. I can print the value in System out normally as a test. but the value is not set in the text field within this method.

Full code here --> https://github.com/loardjulio/SoftFlor.git

  • Julio, provide what you have already done, in the format of a code that is [mcve] so that we can run and test the problem.

  • I also recommend reading: https://pt.meta.stackoverflow.com/a/5485/28595

  • Articuno, Cara thousand pardons. I could see that I’m new here right. I redid the whole topic seeking to meet the standards. I was embarrassed kkkk. Sorry and Thank You

  • Julio, Oce has not yet provided what I suggested, I recommend that you access the link and create a code that is testable and summarized, after all, it is not cool to force those who want to help you to download your entire project and accessing external links. I recommend that you create an example according to the first link.

  • I think I have understood the problem, the problem is that you are using several Jframes, when the recommended is to use only one for the main screen, and modal screens for other secondary functions, such as recovering data, which is the case of your problem, see the answers to the yellow box questions, in it I explain some solutions to problems similar to yours and in one of them teaches how to use modals in java-swing, through Jdialog. s

  • Thank you. Thank you

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.