aspose file tools*
The moose likes Java in General and the fly likes ActionListener Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "ActionListener" Watch "ActionListener" New topic
Author

ActionListener

Sanjiv Kumar
Greenhorn

Joined: Feb 17, 2001
Posts: 5
Hi All,
I m adding actionlistener to a button and opening a dialog in actionperformed.If i m clicking 2-3 times on button the dialog is coming that many times.Have u any idea about it to avoid it.....???
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Check to see if the dialog is already visible on the screen before you create a new one
or
create only one and do nothing but show it in your event handler


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Sanjiv Kumar
Greenhorn

Joined: Feb 17, 2001
Posts: 5
Suppose i click 2-3 times on button before dialog appear. In that case that many times action will performed. i am opening dialog in action performed.so 2-3 dialog is opening.
John Zukowski
Author
Ranch Hand

Joined: Mar 29, 2001
Posts: 88
Create the dialog once. Then when action happens, show it. Don't create the dialog each time.
------------------
John Zukowski Author of "Definitive Guide to Swing for Java 2" and "Java Collections"


John Zukowski Author of <a href="http://www.amazon.com/exec/obidos/ASIN/189311578X/ref=ase_electricporkchop/107-7882751-0234939" target="_blank" rel="nofollow">"Definitive Guide to Swing for Java 2"</a>,<br /><a href="http://www.amazon.com/exec/obidos/ASIN/1893115925/ref%3Dase%5Felectricporkchop/102-5437230-7785719" target="_blank" rel="nofollow">"Java Collections"</a> and <a href="http://www.amazon.com/exec/obidos/ASIN/1893115984/ref%3Dase%5Felectricporkchop/102-5437230-7785719" target="_blank" rel="nofollow">"Learn Java with JBuilder 6"</a>
Scott Appleton
Ranch Hand

Joined: May 07, 2001
Posts: 195
Also, you could toggle setEnabled() on the button in your event catching routine, which should prevent execution of the code after the first click, and only re-enable the button after the dialog returns.
Bill Prentice
Greenhorn

Joined: Mar 06, 2001
Posts: 26
Maybe the point here is that the Dialog is taking a long time to actually arrive on the screen once the button is clicked, is this the case?. If so, it is the event not the button that is the root of the problem.
Ashutosh Uprety
Ranch Hand

Joined: Nov 30, 2000
Posts: 39
set the modal parameter of ur Dialog to true
This will prevent u from clicking on the parent window unless the dialog is closed.
constructors are
public Dialog(Frame parent,String title,boolean modal)
public Dialog(Frame parent,boolean modal)
Sanjiv Kumar
Greenhorn

Joined: Feb 17, 2001
Posts: 5
Originally posted by Ashutosh Uprety:
set the modal parameter of ur Dialog to true
This will prevent u from clicking on the parent window unless the dialog is closed.
constructors are
public Dialog(Frame parent,String title,boolean modal)
public Dialog(Frame parent,boolean modal)

Hi Ashutosh
ThanQ for your suggestion.
I am doing same thing. But problem is if i clicking more than one times before coming the dialog then it is coming more than one Dialog.
With Regards
Sanjiv

Sanjiv Kumar
Greenhorn

Joined: Feb 17, 2001
Posts: 5
Originally posted by Bill Prentice:
Maybe the point here is that the Dialog is taking a long time to actually arrive on the screen once the button is clicked, is this the case?. If so, it is the event not the button that is the root of the problem.

Hi Bill Prentice
Yah i think u are right. Because i am doing modal dialog. In modal dialog we can not do anything before closing the that dialog. If the case is that then what will be solution???
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ActionListener