my dog learned polymorphism*
The moose likes Swing / AWT / SWT and the fly likes How to ignore more than one ActionEvents Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to ignore more than one ActionEvents" Watch "How to ignore more than one ActionEvents" New topic

How to ignore more than one ActionEvents

Anne Forumer
Ranch Hand

Joined: Apr 19, 2004
Posts: 72
A JButton has an ActionListener registered to it.

When handling low-level MouseEvents one can intercept double-clicks and prevent them from doing anything. But how can one do the same thing with higher-level ActionEvents? Multiple ActionEvents are generated with multiple clicks.

In case the answer is to take care of this by writing your own MouseEvent handlers to consume double-clicks, does one have to handle multiple-clicks in all methods of MouseListener?

Don Kiddick
Ranch Hand

Joined: Dec 12, 2002
Posts: 580
Why don't you store the time, when your action listener code executes (by a call to System.currentTimeInMillis()). Each execution you check that the time is at least, say 500 milliseconds later than the last execution, and if not ignore the event.

It is sorta covered in the JavaRanch Style Guide.
subject: How to ignore more than one ActionEvents
Similar Threads
open new window
XML generation for data in a table
JButton in JTable
how to highlight(change color) of the button and its neighbours when it is clicked
How can I make an executable file?