This is javax.swing.plaf.basic.BasicButtonListener:

 public void mousePressed(MouseEvent e) {
  if ( SwingUtilities.isLeftMouseButton(e) ) {
     AbstractButton b = (AbstractButton) e.getSource();
     ButtonModel model = b.getModel();
     if (!model.isEnabled()) {
  // Disabled buttons ignore all input...
  return;
     }

     // But because of the mouseDragged hack above, we can't do setArmed
     // in mouseEnter. As a workaround, set it here just before setting
     // focus.
     model.setArmed(true);
     model.setPressed(true);
     if(!b.hasFocus()) {
  b.requestFocus();
     }
 }
 }

I suggest overriding your ButtonUI to return a subclass of
BasicButtonListener or MetalButtonListener (assuming that you are using
Metal L&F), getting mousePressed to set a flag (and mouseReleased to unset
it), and changing the above test to (!model.isEnabled || (flag == true)).

Only subclass if you need to create a new type of button. (Not the case,
here.)

-----Original Message-----
From: Vincent Vandenschrick <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED] <[EMAIL PROTECTED]>
Date: Thursday, June 07, 2001 11:41
Subject: Re: Button multiple "fireActionPerformed"


>Thanks for the answers.
>I do aggree on all points. The problem is that I can't act on a
>"per-listener" basis. I really need to get this to work for all JButtons by
>subclassing the component...
>
>Any idea ?
>Thanks a lot.
>
>Vincent.
>
>
>----- Original Message -----
>From: "Greg Munt" <[EMAIL PROTECTED]>
>To: "Vincent Vandenschrick" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
>Sent: Wednesday, June 06, 2001 4:34 PM
>Subject: Re: Button multiple "fireActionPerformed"
>
>
>> Why it won't work:
>>
>> 1. The two mouse clicks are two separate events
>>
>> 2. Event 1 calls your fireActionPerformed, which disables the button,
>calls
>> the real fireActionPerformed, then enables the button again.
>>
>> 3. Event 2 still causes things to happen, because the events are stored
in
>a
>> queue, acted on in order.. So by the time the system comes to process
>event
>> 2, the last bit of event 1 has re-enabled the button.
>>
>> (Please correct me if I am inaccurate with that.)
>>
>> How it might work depends on what happens as a result of pressing the
>> button. For example, say it shows a frame. Get your listener to detect
>when
>> the frame is opened and closed. Don't allow more frames to be opened if
>> there is one open already.
>>
>>     -----Original Message-----
>>     From: Vincent Vandenschrick <[EMAIL PROTECTED]>
>>     To: [EMAIL PROTECTED] <[EMAIL PROTECTED]>
>>     Date: Wednesday, June 06, 2001 03:13
>>     Subject: Button multiple "fireActionPerformed"
>>
>>
>>     Hi list,
>>
>>     I appologize if the question has already been asked and answered. It
>> seems to be very simple but I can't figure out how to do it.
>>
>>     I have a JButton with an action listener registered. The goal is to
>> prevent a "multiple click" on the button to multiply the
>> "fireActionPerformed".
>>     My first idea was to override the fireActionPerformed method to first
>> disable the button, really fireActionPerformed and then re-enable the
>> button. This doesn't work since the multiple cliks seem to be forwarded
to
>> the eventDispatchThread before the button gets disabled.
>>
>>     Did any one ever solve this problem ?
>>     Thanks for all your answers.
>>
>>     Vincent.
>>
>>
>> _______________________________________________
>> Swing mailing list
>> [EMAIL PROTECTED]
>> http://eos.dk/mailman/listinfo/swing
>>
>
>_______________________________________________
>Swing mailing list
>[EMAIL PROTECTED]
>http://eos.dk/mailman/listinfo/swing

_______________________________________________
Swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/swing

Reply via email to