Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ActionListener

 
Sanjiv Kumar
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Sanjiv Kumar
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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"
 
Scott Appleton
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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???
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic