开发者

JButton "stay pressed" after click in Java Applet

开发者 https://www.devze.com 2023-03-07 21:45 出处:网络
I have a JButton in my Java Applet. After pressing it, A开发者_如何学JAVActionListener have to make huge amount of actions. So, because of it, when user clicks the button, it \"stay pressed\" for a wh

I have a JButton in my Java Applet. After pressing it, A开发者_如何学JAVActionListener 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消