lol - you'll kick your own butt here...
as you know, swing will queue events when the dispatch thread is hung... You ATTEMPT TO create a seperate thread to disable the button and wait to re-enable. However, this is not acting multithreaded as you are calling the run method of this thread object instead of the start method. calling the run method does just that - it calls the run method in the same thread!!!
Now here's a much simpler solution (excuse the nasty exception handling, and the name change) example only:
package com.dana.nothing;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.reflect.*;
public class Nothing extends JFrame {
JButton myButton = new JButton();
public Nothing() throws Throwable {
try {
jbInit();
}catch(Exception e) {
e.printStackTrace();
}
this.pack();
this.setVisible(true);
}
private void jbInit() throws Exception {
myButton.setText("jButton1");
myButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
myButton_actionPerformed(e);
}
});
this.getContentPane().setLayout(new FlowLayout());
this.getContentPane().add(myButton, null);
}
void myButton_actionPerformed(ActionEvent e) {
System.out.println("Button clicked");
myButton.setEnabled(false);
new Thread(new Runnable() {
public void run() {
try {
//i dont understand why you don't just do your
//business logic here instead of sleeping,
//but this is what you requested...
Thread.sleep(4000);
} catch (InterruptedException ex) {
}
try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
myButton.setEnabled(true);
}
});
} catch (InvocationTargetException ex) {
} catch (InterruptedException ex) {
}
}
}).start();
//here is where you could launch a thread
//to do business logic, but it makes more sense up above
}
public static void main(
String[] args) throws Throwable {
new Nothing();
}
}