Revalidate and repaint - Java Swing
我有一个要添加JLabel的JPanel。然后,我想删除所有的JLabel并添加一些新的JLabel。
因此,我执行以下操作:
1 2 3 4 5 |
这很好。当我像下面这样启动新线程时,出现了我的问题:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | panel.removeAll();panel.repaint(); (1)panel.add(new JLabel("Add something new"); panel.revalidate(); //new thread to start - this thread creates new JLabels that should appear under (1) firstProducer.start(); try { firstProducer.join(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } |
然后原始JLabels的输出仍然可见。我已经读到,重新验证过程是一个长期运行的任务,因此firstProducer线程正在启??动,而
重新验证正在进行中,并且发生了冲突。解决此问题的最佳方法是什么?
问题是
中所述
Waits for this thread to die.
因此,您将阻塞事件分发线程,直到其他
有关更多信息,请咨询Swing并发教程