Refresh JtextArea

0

Good morning, I have a java code that sends data to a JtextArea the problem is that when you re-run the method and send other data the new data is well displayed, but when you select them in the jtextArea it shows me the ones I sent by first time.

Thank you in advance for the attention given

Enclosed fragmeto code

btnCalcular.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            try {
                calculadora nuevo = new calculadora();
                // Capturamos datos
                double pcompra= Double.parseDouble(txtCompra.getText());
                nuevo.setDatoUsuario(pcompra);
                double pestimado=Double.parseDouble(txtPorcentaje.getText());
                nuevo.setPorcentajeEstimado(pestimado);
                //Ejecutamos el metodo
                nuevo.calculo();
                //Creamos el JTextArea
                JTextArea textArea = new JTextArea();
                frmCalcucripto.getContentPane().add(textArea);
                textArea.setEditable(true);
                textArea.setBounds(10, 150, 245,90);
                textArea.setBackground(new Color(0,150,136));
                textArea.setForeground(Color.WHITE);
                textArea.setFont(new Font("Tahoma", Font.BOLD, 12));
                //Enviamos los datos al JTextArea
                textArea.setText("Precio inicial: "+txtCompra.getText()+"\n"+"Porcentaje estimado: "+txtPorcentaje.getText()+" %"+"\n"+"Porcentaje calculado: "
                +nuevo.getDatoRedondeado()+"\n"+"Precio final: "+nuevo.getDatoFinal()); 
            } 
            catch (Exception e) {
                JOptionPane.showMessageDialog(null, "Se ha presentado una anomalía en los datos ingresados:  "+e.getMessage());
            }           
        }
    
asked by Dicruz 07.01.2018 в 17:45
source

1 answer

0

The problem is that every time you call the method you create a new JtextArea, try to create it only the first time you call it.

    
answered by 07.01.2018 / 19:48
source