<AWT Dev> Question regarding EventQueue.getNextEvent() and postEvent()
Roman Kennke
roman at kennke.org
Mon Nov 14 03:14:43 PST 2011
Hi there,
I see a discrepancy in the implementation of EventQueue's postEvent()
vs. getNextEvent() (or peekEvent() for that matter).
Suppose we have a stack of 2 event queues, eq1 and eq2. eq1 is the
system event queue, i.e. the bottom of the stack. eq2 is pushed on top
of it.
Now, if I call Toolkit.getSystemEventQueue() what I get is eq1 and when
I call postEvent(), it goes to the top of the stack, i.e. eq2, and posts
the event in that queue.
However, peekEvent() and getNextEvent() don't do the same. When I call
getNextEvent() or peekEvent() on the eq1, it does never see the event I
just posted before.
I find this a bit irritating. When I post an event on the sys EQ, I
would expect the event to appear in the same EQ (from the point of view
of my code, I only ever see this system EQ). The fact that another EQ is
pushed on top of this changes this behavior. I would like to understand
if there is a reason behind this implementation discrepancy, and if yes,
what it is.
Find attached an example that exposes the problem. When you change the
queue in the inner while loop to query eq2 directly, it works, otherwise
the even never shows up in that loop. (Yes I know there's also the EDT,
and I should probably change the example so that the inner loop runs in
the EDT, but it would be the same).
Cheers, Roman
-------------- next part --------------
A non-text attachment was scrubbed...
Name: EQTest.java
Type: text/x-java
Size: 649 bytes
Desc: not available
Url : http://mail.openjdk.java.net/pipermail/awt-dev/attachments/20111114/b8747b1d/EQTest.java
More information about the awt-dev
mailing list