tags:

views:

29

answers:

1

Hi

Is the AbstractButton.doClick need to be on dispatching thread ?

If I look at the jdk 6 source I read :

   public void doClick(int pressTime) {
        Dimension size = getSize();
        model.setArmed(true);
        model.setPressed(true);
        paintImmediately(new Rectangle(0,0, size.width, size.height));
        try {
            Thread.currentThread().sleep(pressTime);
        } catch(InterruptedException ie) {
        }
        model.setPressed(false);
        model.setArmed(false);
    }

I suppose it's bad to exec the sleep method on the edt, so I suppose the doClic method must not be in edt, but I don't find any documentation on this point ?

Thanks.

+1  A: 

Invoking the doClick() method will ultimately result in an ActionEvent being generated and therefore your ActionListener will be invoked. All listeners should execute on the EDT.

I suppose it's bad to exec the sleep method on the edt,

This sleep value is expected to be mmilliseconds, not minutes to simulate the user clicking on a button so you will see the button painted in its pressed state and then back to its normal state. So blocking the EDT for a few MS is not a problem.

camickr