简体   繁体   中英

JButton “stay pressed” after click in Java Applet

I have a JButton in my Java Applet. After pressing it, ActionListener have to make huge amount of actions. So, because of it, when user clicks the button, it "stay pressed" for a while (sometimes even 5 minuts) instead of disable itself immidiately (it disable itself after these 5 minuts).

public void actionPerformed(ActionEvent e) {
  JButton.setEnabled(false);
  //...
}

I don't want user to see that. I would like all these action execute in the background. What can I do to achive it?

You should do such intensive tasks in another thread, not the dispatcher thread.

Some useful reading:Worker Threads and SwingWorker

The problem is that the GUI-Thread is busy and will not repaint the component until processing has finsihed

You could do the activities in a backgroud thread.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM