当动作列表器是一个线程时,JList没有正确更新

时间:2013-05-13 18:13:50

标签: java swing actionlistener jlist event-dispatch-thread

我有一个ActionListener按钮,它是一个Thread。在这个线程的run方法中,我尝试更新JList setListData()方法,但它不会更新。它使用的是组合框而不是JList。 我也尝试在invokeLater线程中执行此操作但不起作用。

class Main{
     JButton btn = new JButton();
     JList jList = new JList();
     btn.addActionListern(new ActionListener(){
         actionPerformed(ActionEvent e){
              new ItThread().start();
          }
    });




    class ItThread extends Thread{

        run(){
             String [] data = new String[2];
             data[0] = "it"
             data[1] ="itd";
             jList.setListData(data);
        }
    }


}

0 个答案:

没有答案
相关问题