Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 705
Jerry Avatar asked Mar 21 '26 16:03

Jerry


2 Answers

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

Some useful reading: Worker Threads and SwingWorker

like image 114
mdrg Avatar answered Mar 23 '26 04:03

mdrg


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.

like image 39
king_nak Avatar answered Mar 23 '26 06:03

king_nak