How I append text to textarea with using swingworker class?

前端 未结 1 1916
不思量自难忘°
不思量自难忘° 2020-12-20 10:51

I want to append text in loop with swingworkerclass in java. for ex :

while(true)
{
     mytextarea.append(\"sometext\");
     if(some_condition)
     {break         


        
相关标签:
1条回答
  • 2020-12-20 11:17

    SwingWorker is not right here. Your code is not running in the EDT so you doesn´t see updates. You can use SwingUtilities.invokeLater(...) to execute your code in the EDT. But do not execute the whole while-loop in the EDT because this will block it and no updates / events (repaints, Mouseclicks). Here is a simply code-example:

        while(true) {
            SwingUtilities.invokeLater(new Runnable{
                public void run() {
                    textfield.setText(....);
                }
             });
             if(condition) break;
         }
    

    For more Information look at http://java.sun.com/products/jfc/tsc/articles/threads/threads1.html or this book: http://filthyrichclients.org

    0 讨论(0)
提交回复
热议问题