Results 1 to 11 of 11
  1. #1
    ShedoSurashu is offline Member
    Join Date
    Nov 2013
    Posts
    13
    Rep Power
    0

    Default How do I prevent events from stacking while JOptionPane is open?

    Using JInput, I pop up a JOptionPane upon button press. Repeatedly pressing the button seems to not be working (which is what I'm after). However, as soon as I close the JOptionPane, all the previous presses I did seem to have stacked and are being one by one for each press that I did before.

    I want to know how I can completely prevent those from getting stacked.

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,457
    Blog Entries
    7
    Rep Power
    20

    Default Re: How do I prevent events from stacking while JOptionPane is open?

    A JOptionPane is a modal dialog, so no events from outside this dialog are supposed to be handled, nor 'stacked'; you have to show us a bit of (relevant) code.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    ShedoSurashu is offline Member
    Join Date
    Nov 2013
    Posts
    13
    Rep Power
    0

    Default Re: How do I prevent events from stacking while JOptionPane is open?

    Quote Originally Posted by JosAH View Post
    A JOptionPane is a modal dialog, so no events from outside this dialog are supposed to be handled, nor 'stacked'; you have to show us a bit of (relevant) code.

    kind regards,

    Jos
    Well since I have it on GitHub anyway, here's the problem code:

    https://github.com/CoffeeCone/GameBo...Main.java#L370

    On line 370, I am calling MsgBox which is a class I use for displaying JOptionPanes. The problem is, while the JOptionPane is open, I can still press buttons in the gamepad and after closing the open JOptionPane, a new one immediately pops up with the identifier of the buttons that I have pressed while it was open awhile ago.

    Example scenario, I press button 0 and JOptionPane myAlert shows up with a message "button 0 has been pressed". While myAlert is still open and I press button 1 and button 2, as soon as I close myAlert, a new one pops immediately, this time with the message "button 1 has been pressed" and then after that "button 2 has been pressed". That's what I meant by the events stacking.

    It's really hard to explain in words but I hope you got the gist of my problem. xD

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,343
    Rep Power
    25

    Default Re: How do I prevent events from stacking while JOptionPane is open?

    Please make a small, complete program that compiles, executes and shows the problem.


    Is the JOPtionPane called on the EDT?
    If you want to suppress other buttons being alive to presses. disable them to prevent their being pressed when you don't want them pressed
    Last edited by Norm; 11-19-2013 at 02:20 PM.
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    ShedoSurashu is offline Member
    Join Date
    Nov 2013
    Posts
    13
    Rep Power
    0

    Default Re: How do I prevent events from stacking while JOptionPane is open?

    Quote Originally Posted by Norm View Post
    Please make a small, complete program that compiles, executes and shows the problem.

    Is the call to JOptionPane done on the EDT?
    What does EDT mean?

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,343
    Rep Power
    25

    Default Re: How do I prevent events from stacking while JOptionPane is open?

    That's the name for the thread the JVM uses to control the GUI.

    Ask a Search engine for all the details.
    If you don't understand my response, don't ignore it, ask a question.

  7. #7
    ShedoSurashu is offline Member
    Join Date
    Nov 2013
    Posts
    13
    Rep Power
    0

    Default Re: How do I prevent events from stacking while JOptionPane is open?

    Quote Originally Posted by Norm View Post
    If you want to suppress other buttons being alive to presses. disable them to prevent their being pressed when you don't want them pressed
    I think you mean user interface buttons? If so then no, I'm talking about buttons on the gamepad controller connected via USB cable. When I press a button on the gamepad, an event is fired. I'd try to provide a sample but you would need to have a gamepad connected to your laptop/pc to see it.

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,343
    Rep Power
    25

    Default Re: How do I prevent events from stacking while JOptionPane is open?

    Sorry, I don't go to offsite links. can you make a small, complete program that compiles, executes and shows the problem.
    If you don't understand my response, don't ignore it, ask a question.

  9. #9
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,457
    Blog Entries
    7
    Rep Power
    20

    Default Re: How do I prevent events from stacking while JOptionPane is open?

    Quote Originally Posted by ShedoSurashu View Post
    Well since I have it on GitHub anyway, here's the problem code:

    https://github.com/CoffeeCone/GameBo...Main.java#L370

    On line 370, I am calling MsgBox which is a class I use for displaying JOptionPanes. The problem is, while the JOptionPane is open, I can still press buttons in the gamepad and after closing the open JOptionPane, a new one immediately pops up with the identifier of the buttons that I have pressed while it was open awhile ago.

    Example scenario, I press button 0 and JOptionPane myAlert shows up with a message "button 0 has been pressed". While myAlert is still open and I press button 1 and button 2, as soon as I close myAlert, a new one pops immediately, this time with the message "button 1 has been pressed" and then after that "button 2 has been pressed". That's what I meant by the events stacking.

    It's really hard to explain in words but I hope you got the gist of my problem. xD
    So that gameboy is another device that 'pushes' the external event and waiits until it is 'processed'? For a quick hack you could set a global flag telling the receiver to discard all incoming stuff; you set that flag just before you display anything modal and you reset it again after the modal dialog is gone again.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  10. #10
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,967
    Rep Power
    19

    Default Re: How do I prevent events from stacking while JOptionPane is open?

    How are you listening for the gamepad events?
    Is there a thread somewhere for that?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  11. #11
    ShedoSurashu is offline Member
    Join Date
    Nov 2013
    Posts
    13
    Rep Power
    0

    Default Re: How do I prevent events from stacking while JOptionPane is open?

    Quote Originally Posted by JosAH View Post
    For a quick hack you could set a global flag telling the receiver to discard all incoming stuff; you set that flag just before you display anything modal and you reset it again after the modal dialog is gone again.

    kind regards,

    Jos
    I was about to say I tried that before and it didn't work. However, this time around I tried placing the implementation on a separate method and calling it using a timer and now it worked! Thanks!

Similar Threads

  1. Stacking JPanels
    By verd in forum AWT / Swing
    Replies: 4
    Last Post: 07-26-2012, 08:01 PM
  2. Keeping a JOptionPane window open after selection.
    By Joshuak in forum New To Java
    Replies: 1
    Last Post: 12-10-2011, 08:11 AM
  3. Replies: 5
    Last Post: 08-15-2011, 06:10 PM
  4. how to prevent open folder in run time
    By syedabu in forum NetBeans
    Replies: 0
    Last Post: 03-18-2010, 04:09 AM
  5. Replies: 0
    Last Post: 01-21-2008, 01:29 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •