How to display changing text in Java Swing (ie, display time with changing seconds)

江枫思渺然 提交于 2019-12-04 16:49:25

Use the javax.swing.Timer to ensure that updates to the Swing component occur on the EDT.

Timer t = new javax.swing.Timer(2000, new ActionListener(){
    @Override
    public void actionPerformed(ActionEvent e){
        yourLabel.setText(...);
    }
});
t.start();
Riduidel

Use Swing Timer. As the tutorial explains, it is the required tool for the job.

The only alternative to their use is the embedding of a SwingUtilities.invokeLater()or SwingUtilities.invokeAndWait() in a TimerTask.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!