java set delay to change imageicon

前端 未结 2 495
猫巷女王i
猫巷女王i 2021-01-29 10:11

i\'m trying to set a delay when a button is pressed to set an imageicon to a certain image then set another delay so that another image would be set, all of this by single click

2条回答
  •  悲&欢浪女
    2021-01-29 10:59

    You should try executing the code that sets the image in the event dispatch thread using InvokeLater.

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            lblNewLabel.setIcon(and);
        }
    });
    
    sleeep();
    
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            lblNewLabel.setIcon(and);
        }
    });
    

提交回复
热议问题