Flush pending AWT events programmatically

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.

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

Similar Messages

  • Can you define an event programmatically?

    Does anyone know how to define an event programmatically for a form object using JavaScript? My example is this:
    I am passing form fields to a validation function in a JavaScript object by calling scriptObj.addToValidation(this); from the field initialize event.
    The field object is added to a JavaScript array so I can check for null values of potentially hundreds of fields with one block of code. What I also want to do is define the click and enter events for each object programmatically from the addToValidation(obj) function while iterating through the array. This way I wont need to add code in each field in the design view, my goal is to take as much code out of the form fields as possible and put it into a script object using an object-oriented approach.
    A path I was looking down was trying to access the event by: fieldObject[i].event__change = ... If you print the event__change or event__enter to the javascript console you can see it is an XFAObject but I cant find any doco about these objects and dont know if Im on the right track.
    Hopefully this makes sense, please talk to me LC gurus!!

    Hi Thom,
    Thanks for your insights. Adding 2500 scripts through field duplication would be a solution, in which each field call a generic function according to:
    scriptObject.DoStuff(this, xfa.event);
    It's doable, although it's against my religion. :>
    I found out I can still propagate events down the object chain (or "up" according to Adobe's documention, a metaphor I find counter-intuitive) by manually adding the tag
    listen="refAndDescendents"
    to an event tag of the parent subform. To my relief, even though subforms don't listen to Change activities, the event does get propagated to children who do.
    On add-ins to Designer - are you referring to the experimental macro feature introduced in ES2?
    http://blogs.adobe.com/formfeed/2010/01/designer_es2_macros.html

  • How to enqueue custom AWT event?

    hi,
    in my applet I need to use custom AWT events. I subclass them from java.awt.AWTEvent and set their id to higher as AWTEvent.RESERVED_ID_MAX - as recomended in documentation.
    But how to enqueue such event? A tried to use following approach:
    getToolkit().getSystemEventQueue().postEvent( myEvent );
    and it works fine - but only in browsers usings Sun's VM implementation. In browsers using Microsoft's VM I'm getting following exception:
    com.ms.security.SecurityExceptionEx[matlu/client/ClientConnection.enQueue]: Event queue access denied.
    So the question is: is there any other way to enqueue custom event, which will keep Microsoft's security manager happy?
    thak you very much
    Lubo Matecka

    I know it must be visible... (But it doesnt have to be bigger than 1 pixel...)
    The code I posted is just to illustrate the idea.
    If you need to post multiple events you just replace the AWTEvent member with a LinkedList (or some similar FIFO).
    Then in postEvent you do theLinkedList.addFirst(yourEvent)
    And in paint() you do AWTEvent ev = (AWTEvent)theLinkedList.removeLast();
    process ev.
    if(theLinkedList.size() > 0)
       repaint();Yes. I have run into the same problem, and I did not use the repaint- trick...
    My applet communicates with the server in a separate thread. When a response receives the communication thread should post an event to the AWT- thread to get the response processed.
    My solution here is to process the thread in the communicator- thread. This is a bad solution because it might create multithreading bugs.... but it has proven to work ok in practice.
    Another example is like this. The use presses the mouse at Component B so that:
    1 Component A gets a focusLost event.
    2 Component B gets a mousePressed.
    3 I want to do something in component A that should be done after component B has processed the mousePressed event. This can be solved without using events. You just have to write some more code (You are already in the right thread).

  • How to "kill" AWT Event Queue thread without using System.exit()?

    When I run my program and the first GUI window is displayed a new thread is created - "AWT-Event Queue". When my program finishes, this thread stays alive and I think it causes some problems I have experienced lately.
    Is there any possibility to "kill" this thread without using System.exit() (I can't use it for some specific reasons)

    All threads are kept alive by the JVM session. When you use System.exit(int) you kill the current session, thus killing all threads. I'm not sure, though...
    What you could do, to make sure all threads die, is to make ever thread you start member of a thread group. When you want to exit you app, you kill all the threads in the thread group before exit.
    A small example:
    //Should be declared somewhere
    static ThreadGroup threadGroup = new ThreadGroup("My ThreadGroup");
    class MyClass extends Thread {
    super(threadGroup, "MyThread");
    Thread thread = new Thread(threadGroup, "MySecondThread");
    void exit() {
    //Deprecated, seek alternative
    threadGroup.stop();
    System.exit(0);
    }

  • Anonymous awt.event

    Hello, This code is copied from a Sun tutorial and I am getting a compiler error that states that
    init:
    deps-jar:
    Compiling 1 source file to C:\271\SwingPaintDemo1\build\classes
    C:\271\SwingPaintDemo1\src\SwingPaintDemo1.java:67: addMouseMotionListener(java.awt.event.MouseMotionListener) in java.awt.Component cannot be applied to (<anonymous java.awt.event.MouseAdapter>)
    addMouseMotionListener(new MouseAdapter() {
    1 error
    BUILD FAILED (total time: 0 seconds)
    Here is the code: Can someone help please?
    * SwingPaintDemo1.java
    * Created on October 8, 2007, 8:07 AM
    * To change this template, choose Tools | Template Manager
    * and open the template in the editor.
    package painting;
    import javax.swing.SwingUtilities;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.BorderFactory;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseMotionListener;
    import java.awt.event.MouseMotionAdapter;
    public class SwingPaintDemo1 {
        public static void main(String[] args) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    createAndShowGUI();
        private static void createAndShowGUI() {
            System.out.println("Created GUI on EDT? "+
            SwingUtilities.isEventDispatchThread());
            JFrame f = new JFrame("Swing Paint Demo");
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.add(new MyPanel());
            f.pack();
            f.setVisible(true);
    class MyPanel extends JPanel {
        private int squareX = 50;
        private int squareY = 50;
        private int squareW = 20;
        private int squareH = 20;
        public MyPanel() {
            setBorder(BorderFactory.createLineBorder(Color.black));
            addMouseListener(new MouseAdapter() {
                public void mousePressed(MouseEvent e) {
                    moveSquare(e.getX(),e.getY());
            addMouseMotionListener(new MouseAdapter() {
                public void mouseDragged(MouseEvent e) {
                    moveSquare(e.getX(),e.getY());
        private void moveSquare(int x, int y) {
            int OFFSET = 1;
            if ((squareX!=x) || (squareY!=y)) {
                repaint(squareX,squareY,squareW+OFFSET,squareH+OFFSET);
                squareX=x;
                squareY=y;
                repaint(squareX,squareY,squareW+OFFSET,squareH+OFFSET);
        public Dimension getPreferredSize() {
            return new Dimension(250,200);
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);      
            g.drawString("This is my custom Panel!",10,20);
            g.setColor(Color.RED);
            g.fillRect(squareX,squareY,squareW,squareH);
            g.setColor(Color.BLACK);
            g.drawRect(squareX,squareY,squareW,squareH);
    }

    Use
    addMouseMotionListener(new MouseMotionAdapter()

  • Synchronize AccessBridge thread with AWT event thread?

    Hi,
    I am a beginner in Java Access Bridge.
    I am writing a program that runs with Java Web Start and uses JFC Swing. For system monitoring purpose my company uses HP OpenView. Probe Builder is used for recording a probe for the application. The probe will be run at regular intervals to check if anything is broken. As I understand Probe Builder uses Java Access Bridge to record & control the application flow.
    Without Java Access Bridge my program runs fine. But when I run it with Probe Builder I occasionally catch some exceptions that indicate that there are two threads running over my gui classes at the same time, the AWT event thread and another thread that comes from com.sun.java.accessibility.AccessBridge.run.
    Since my classes are not thread safe (like all the Swing classes) there are race conditions that result in a NullPointerException.
    My question is that how can I make sure that only one thread at a time is running over my code? Can I somehow make Java Access Bridge run with the AWT event thread? Or do I have to synchronize all my methods - I want to avoid this since I am not sure that this can be done perfectly.
    I will appreciate any help.
    Thanks
    Message was edited by:
    karneim

    Maybe there is some other way to "kill" this thread because for some specific reasons I don't think I will be able to use System.exit(). This reason is - I'm using this Java program in Lotus Notes (don't know if you have had any experience with this) and if I call System.exit() then some important clean-up (garbage collection) won't be done.

  • AWT Event Listener not listening...

    Hi,
    I'm having problems with an AWT Event Listener on a JFrame.
    Basically, im making a tank game, so the first screen to appear is an inventory screen. The when you click start on this screen, you create a GameScreen which extends JFrame. i have an AWT Event Listener added to this frame using this code:
    Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener(){
    public void eventDispatched(AWTEvent e) {
    if(((KeyEvent)e).getKeyCode() == KeyEvent.VK_DOWN && e.getID() == KeyEvent.KEY_PRESSED)
    It's checking events on the arrow keys and the tab and enter keys.
    So when the this round of the game has finished, i setVisible to false, and make the inventory visible again.
    The problem is, when i set make the GameScreen visible again, the listeners aren't working.
    It seems to be working fine for 'enter', that is VK_ENTER, but not for the arrow keys...
    Any1 have any ideas??
    Any help would be great!
    Thanks,
    D.

    I am willing to bet that your problem lies in that once you return the main game screen from the inventory screen that you need to set the focus back to the main game screen. I believe, as events go, the component that has the focus is the one that will receive the events and process them according to their listener code. As I am not sure where your focus goes once you close the inventory screen and open the main screen, it could be that the wrong component has the focus.
    As far as getting the focus to the correct component is concerned, I remember myself and Malohkan having a discussion as to how to get this to work, and he came up with a work-around. That thread is somewhere in this forum. I'm not sure if it will solve your problem, but it might be something worth looking into.
    -N.

  • Running JUnit tests from AWT Event Quene

    Anyone know how to run JUnit tests from the AWT Event Queue? JFCUnit is overkill; I'm just looking for a TestRunner that runs on a different thread. I can delve into the JUnit documentation but, with luck, someone who's been through this before can spare me the trouble. Also, anyone else get a server error when searching for "JUnit event dispatch" on this forum?

    JUnit 3 version:
    import java.util.concurrent.atomic.AtomicReference;
    import javax.swing.SwingUtilities;
    import junit.framework.TestCase;
    public abstract class EDTTestCase extends TestCase {
         * Overriding this method guarantees that setUp(), tearDown(), and all
         * tests run on the EDT.
        @Override
        public void runBare() throws Throwable {
            final AtomicReference<Throwable> problem = new AtomicReference<Throwable>();
            if (!SwingUtilities.isEventDispatchThread()) {
                SwingUtilities.invokeAndWait(new Runnable() {
                    public void run() {
                        try {
                            runBare();
                        catch (Throwable throwable) {
                            problem.set(throwable);
                if (problem.get() != null) {
                    throw problem.get();
            else {
                super.runBare();
    }

  • Updating component within awt-event thread of another component

    Hi,
    I'm having trouble updating (repainting) a component inside the awt-event thread of another component. The component I want to update is a JFrame with a JLabel that lists the progress of the original component's action that triggered the event. I can get the frame to pop up but it's content is never fully painted and never refreshed.
    I've tried using invokeLater() (the frame ran after the original awt-event had finished) and invokeAndWait() (blocked the original awt-event) and running the computational intensive parts of the original component's action in SwingWorker threads (no difference) but all to no avail.
    What I want to do is similar to a progress bar so I think it should possible. Any suggestions? Thanks, Matt

    Are you calling yield() or sleep(...) on your Thread?

  • MACOS 10.4: Solve AWT Event queue hangup

    Hi,
    I'm having trouble with the AWT eventqueu. On MacOS 10.4, using Java 5 Runtime, my applet sometimes blocks. When looking at the threadstack, the deadlock always appears in the Event Loop, dispatching an AWT event, blocking in the CGlobalCursorManager._updateCursor call. In fact the CGlobalCursorManager.findHeavyweightUnderCursor Native call.
    I already tried some workarounds:
    - overwrite the validate method of my custom AWT components. Making sure that they do not block forever. This solves the problem for events coming through the overidden component, but it has to work for every event that might trigger the GlobalCursorManager.
    I had some possible solutions for which I would like some pro's and con's in this forum:
    1. I could try to kill the event loop. Is it possible to quit the event loop and restart it from within the applet ?
    2. Can I force each AWT container to use another implementation of the validate method ?
    3. Can I set another, customized, CGlogalCursorManager ?
    4. Other possibilities ?
    Thanks in advance for all those responding.

    I think you mean that I can override the validate method for each custom UI object separately.
    That's a possibility, but I was looking for a more general solution. If possible, I would to extends one
    class. E.g. can I set another event queue ? That way, I could make a custom event queue in case of a Mac OS browser.

  • Invoke an awt event from outside the swing application

    Is it possible to invoke an awt event triggered from outside the swing app? I am trying to implement a use case where i have to open a new tab in an already running swing app when a user clicks on a browser link.

    I have a desktop application that was invoked via webstart. The java webstart process started when the user clicked on a link that downloaded the swing application and now it runs in the clients JVM. Each browser click downloades and launches the application that performs a certain function. Now lets say, the user clicks on another link, then i don't want another java application to be launched. I want the same application that executes the function in lets say a new tab.
    Its kind of like you click on a link that somebody sent you in an outlook email. When you click on it and if firefox is already running, the link opens up in a new tab on an already running firefox browser. If firefox was not running, it starts a new firefox process.
    Hope this makes sense

  • How to Trigger  Object type Event programmatically  in ABAP ?

    Experts,
    How to Generate an Object Type Event  programmatically in ABAP ???  We know that SAP std. applications do this by default ,for eg:  Sales Order creation event generation,  similarly , i want to generate an Event  ( SAP or a Z object event ) in my Z program ,, How can i do it ???  Do we have any function module for this one ?  I can do an BDC  CALL TRANSACTION SWUE but i don't want to do that,  i want to use some other method other than BDC.
    Would appreciate your reply . Thanks
    Ashutosh

    Hi Ashutosh, if you are trying to raise a custom event you first must define the event within your business object, using TC SWO1.  If you like you can extend an existing business object or create a new one.  Once your business object is activated and your event is released you should be able to trigger it with the FM 'SWE_EVENT_CREATE'.
    P.S  If you are extending an existing business object, for example BUS2105 and your extended name is ZMBUS2105, refer to the original name, i.e. BUS2105 for the objtype field in the call to 'SWE_EVENT_CREATE'.
    Hope that helps,
    Kevin

  • Problem with java.awt.MouseInfo or java.awt.event.*;

    I have a problem with the MouseInfo class. I think.. because in my mousePressed(MouseEvent event) method, I have this:
         public void mousePressed(MouseEvent event) {
              pInfo = mInfo.getPointerInfo();
              point = pInfo.getLocation();
              pointX = point.getX();
              pointY = point.getY();
              System.out.println("pointer is at: (" + (int)pointX + ", " + (int)pointY + ")");
         }I think you all could figure out what this does. I declared the variables at the top and I implemented MouseListener... when I click it doesnt tell me the X and Y coords.
    Alright, thanks. Any help appreciated.

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class MouseExample extends MouseAdapter implements Runnable {
        @Override
        public void mousePressed(MouseEvent event) {
            int x = event.getX();
            int y = event.getY();
            System.out.println("x=" + x + ", y=" + y);
        @Override
        public void run() {
            JLabel label = new JLabel("Click anywhere", SwingConstants.CENTER);
            label.setPreferredSize(new Dimension(300, 200));
            label.addMouseListener(this);
            JFrame f = new JFrame();
            f.getContentPane().add(label);
            f.pack();
            f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
            f.setLocationRelativeTo(null);
            f.setVisible(true);
        public static void main(String[] args) {
            EventQueue.invokeLater(new MouseExample());
    }

  • "Background Task" "Pending Daemon Events" "Retry Count" setting?

    Hello experts-
    If a scheduled job errors out, I see it under the "Pending Daemon Events" retrying over and over again.
    I don't understand how this is controlled. Is there any where to set:
         - Whether a job attempts to retry or not?
         - The maximum number of times it will retry?
    Thanks in advance!
    Mike
    SAP Sourcing R9 SP13.

    Hi michael
    Below system properties are the ones you need to configure to control the daemon events.
    "system.daemons.events.handled" - A list of the events that this server supports. Glob Regular Expressions are supported. '*' will allow any daemon to run
    "system.daemons.events.repost.max_retries" - The maximum number of times that an event is allowed to be reposted before it is considered to be an error and discarded.
    "system.daemons.alert_daemon.max_idle_minutes" - The maximum number of consecutive minutes that the alert daemon is allowed to be idle.
       Let me know if this helps.
    Thanks,
    Raj.

  • CiscoUnifiedCCXEditor flushing pending logs and traces

    I’m experiencing a UCCX Script Editor 10.5.1 problem.  Stops at "flushing pending logs and traces"….latency is high to the UCCX server like 300ms.
    Tried login anonymous, same problem..
    I have edited this script before, I'm doing a Run As Administrator on the UCCX Script Editor, I can login to AppAdmin with no problems, Agents are taking calls, etc.  Just need to make a script change.
    Can you no longer edit a script being offline?

    Hi Jason,
    have you resolved your issue?
    I'm preparing an upgrade and your problem is worrying :-(
    Have you tried to open the script editor from another PC? Perhaps the problem is there...
    Thanks a lot,
    Andrea

Maybe you are looking for

  • How do I sync the music from my iPhone to iTunes on my mac?

    I got a new macbook and I can't sync the music from my iPhone to iTunes.. How do i do that?

  • Captivate videos created in RH9 cannot be found in RH11

    We just upgraded from RH9 to RH11 and our Captivate videos now have errors "file or directory cannot be found". Any ideas?

  • 10.5.3--Sleep/Standby issue?

    With 10.5.2, when leaving work I would simply drag the mouse to the hot spot to launch my screensaver. My MacBook Pro 17" is set to BETTER PERFORMANCE; it never sleeps, only the display goes to sleep after 15 minutes. I have never had luck with Mac +

  • Join two 8 bit integers and send via Serial Port

    I am trying to join two 8 bit integers and send the result via the serial port. I have a constant of hex value A that I need to join with a value from hex 0 - F (this is based on incoming data) When I use the Join VI, and type cast to change from hex

  • Focus level of BPX

    Hello all, I'm new to the community and my experiences with BPM are -for now- on a theoretical level. I do sense an area of tension of which I would like to hear the opinions of more experienced people. What I've learned so far is that a BPX should t