JButton "stay pressed" after click in Java Applet
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.
精彩评论