Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to replace the AWT EventQueue with own implementation [closed]

Tags:

In order to debug strange behavior in a Swing-application I'd like to replace the AWT EventQueue with my own implementation.

Is this possible? How?

Just in case you are interested:

  • the implementation will be a simple wrapper around the normal Eventqueue, doing some logging.

  • the problem I'd like to debug is a TableCellEditor, which works fine in a little demo app, but when put in the real application, stopCellEditing gets called immediately, due to some event. I'd like to get access to the event in order to find out, where it is comming from.

like image 862
Jens Schauder Avatar asked Jul 01 '10 13:07

Jens Schauder


People also ask

What is java AWT EventQueue?

EventQueue is a platform-independent class that queues events, both from the underlying peer classes and from trusted application classes.

What is EventQueue invokeLater new runnable ()?

invokeLater. Causes runnable to have its run method called in the dispatch thread of the system EventQueue . This will happen after all pending events are processed.


1 Answers

EventQueue has a method called push() that will do exactly what you want. Here is a little demo:

public class QueueTest {     public static void main(String[] args) throws InterruptedException, InvocationTargetException {         EventQueue eventQueue = Toolkit.getDefaultToolkit().getSystemEventQueue();         eventQueue.push(new MyEventQueue());          EventQueue.invokeAndWait(new Runnable() {             public void run() {                 System.out.println("Run");             }         });     }      private static class MyEventQueue extends EventQueue {         public void postEvent(AWTEvent theEvent) {             System.out.println("Event Posted");             super.postEvent(theEvent);         }     } } 
like image 50
rancidfishbreath Avatar answered Oct 16 '22 20:10

rancidfishbreath