Update a JTextArea - Constantly

0

Very Good to all, I have a problem in terms of constantly changing values of a JTextArea, the only thing I want is that by changing several times the value of the component with its method .setText (); I will replace it and show it effectively, but it only always takes me the last value. This action is done through an ActionListener to a button that calls the method that makes the replacement constant. This I do as a quick example, since my intention is to call a method in a different class where in that JTextArea I take a future load bar ... but if I can not even change the value of this I will not be able to do the following ... I appreciate the help very much

    
asked by Andres Rivera 23.01.2018 в 18:27
source

2 answers

0

The error may be in Thread.Sleep since this blocks the main thread of the program ( EDT ), if you really need to use Thread.Sleep test with the following method:

       //RESTO DEL CODIGO
       campocarga.setText("Cargando");
       new Handler().postDelayed(new Runnable(){
           campocarga.setText("Cargando 2");
       }, 2000);

       new Handler().postDelayed(new Runnable(){
           campocarga.setText("Cargando 3");
       }, 2000);
       //RESTO DEL CODIGO
    
answered by 24.01.2018 в 17:15
0

Inquiring a bit, I found that if you use the thread that has the graphical interface for something else, this causes the same interface to be blocked and Android is at least a very bad practice to use the graphic thread for another thing that is not the free flow of this, therefore I saw that the best thing was to divide each process in separate threads ... I tried it and managed to make several processes run while the interface is updated correctly in real time. The class Handlear as I explained above also serves to do something very similar since it starts another thread but is used for some specific things. But it's also a very good solution for my initial problem: D ... Thank you very much.

    
answered by 25.01.2018 в 00:37