3 Replies Latest reply: Mar 17, 2013 9:39 AM by 809259 RSS

    Flush pending AWT events programmatically

    809259
      Hello, everybody.

      Is there a way to flush pending AWT events programmatically? I would like to be able to use it in a code like this:
      if (comp.requestFocusInWindow())
      {
          // flush pending AWT events...
          KeyboardFocusManager focusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
          if (focusManager.getPermanentFocusOwner() == comp)
          {
              // do something...
          }
      }
      Thank you.

      Marcos

      PS: I know I can use a FocusListener in comp, but it is not an option in my case.
        • 1. Re: Flush pending AWT events programmatically
          Maxideon
          You can get to the system EvenQueue and pending AWTEvents with,
          java.awt.Toolkit.getDefaultToolkit().getSystemEventQueue()
          As of java 7, there's a method called #createSecondaryLoop that might be morphed into the kind of functionality you want. I'm basing this off the api description. I have not tried using the method myself.
          • 2. Re: Flush pending AWT events programmatically
            809259
            Maxideon wrote:
            You can get to the system EvenQueue and pending AWTEvents with,
            java.awt.Toolkit.getDefaultToolkit().getSystemEventQueue()
            As of java 7, there's a method called #createSecondaryLoop that might be morphed into the kind of functionality you want. I'm basing this off the api description. I have not tried using the method myself.
            Thank you for the suggestion, Maxideon. I'm using now the solution in this thread:

            http://stackoverflow.com/questions/15451907/flush-pending-awt-events-programmatically

            Marcos
            • 3. Re: Flush pending AWT events programmatically
              809259
              Maxideon wrote:
              You can get to the system EvenQueue and pending AWTEvents with,
              java.awt.Toolkit.getDefaultToolkit().getSystemEventQueue()
              As of java 7, there's a method called #createSecondaryLoop that might be morphed into the kind of functionality you want. I'm basing this off the api description. I have not tried using the method myself.
              Thank you for the suggestion, Maxideon. I'm using now the solution in this thread:

              http://stackoverflow.com/questions/15451907/flush-pending-awt-events-programmatically

              Marcos