There is this article:
Someone jumped the queue! Every now and then it appears that some swing events are processed in the incorrect order in the Event Queue (and nothing gets my blood boiling like when someone cuts into a queue) resulting in strange behavior. This is best illustrated with a small code snippet. Read the snippet below and think carefully in what order you imagine events will take place.
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
repaint();
doSomething();
}
});
Most developers would image that repaint() method will result in a painting operation taking place before the doSomething() method call. However this is actually not the case, the call to repaint() will create a new paint event that will be added to the end of the Event Queue. This new paint event will only be processed (dispatched) after the current Action Event has completed. This means that the doSomething() method will be executed before the new Paint Event on the queue is dispatched.
The key point here is that calls to repaint() will create a new paint event that will be added to the end Event Queue and not processed immediately. This means that no events jump the queue (and my blood can remain at its correct temperature).
My question is, how can I force Swing to do the repaint();
BEFORE doSomething();
?
Also, if there were calls to the repaint()
method WITHIN the doSomething();
they would be executed only after doSomething();
is completed. Is there a way I can pause the doSomething();
mid-executin, then throw in the reapaint();
, get done with it, and then resume doSomething();
?
Only solution I have found so far is this(link), but it's not really practical...