JLabel and JTextField setText is not update

怎甘沉沦 提交于 2019-12-02 10:32:26

I think you mean by "After all the work finish" is loading text from the file(the line you commented). I think this code works fine because you don't do nothing after setting the text. You can use another thread to load text, if it is true.

If oc.oznitelikleriBul() takes a long time, you can code that line and text setting line in a different Thread. But, in that case make sure to run text setting line in an EDT inside the new Thread.

StanislavL

Your long running task is executed in Event Dispatcher Thread which locks the thread where update should be performed. Thus the real update is perfomed only after the task is finished.

Run it in SwingWorker

See e.g.

http://www.javacreed.com/swing-worker-example/

or

How do I use SwingWorker in Java?

Mohammed Hasan

I had same issue. How I solved see below :

I have 2 JFrame classes. Login.java and Employee.java. After login I can not setText() to JTextField object in Employee Form. So what I did ... I used setVisible() employee form with this code. Now I can refresh my JTextField.

Thanks and I hope it will resolve the issues.

java.awt.EventQueue.invokeLater(new Runnable() {
   public void run() {
        new Employee().setVisible(true);
   }
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!