Jerry
Jerry

Reputation: 31

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?

Upvotes: 3

Views: 2550

Answers (2)

king_nak
king_nak

Reputation: 11513

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.

Upvotes: 4

mdrg
mdrg

Reputation: 3412

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

Some useful reading: Worker Threads and SwingWorker

Upvotes: 8

Related Questions