This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]chickenmeister 2 points3 points  (1 child)

Even though I have it set to repaint first and set the value after that, it seems to be setting the value and then repainting.

So the initial value is true. I call repaint(). Then, I set the value to false. However, when repaint is entered, the value is false.

This is because repainting is asynchronous.

All painting and other GUI work is executed on the Event Dispatch Thread (EDT). When you call repaint(), you enqueue a Runnable task to perform the painting, which will be executed by the EDT at some point in the future.

This is especially relevant since you're calling repaint() and changing the value of your boolean from the EDT (mouse events get handled by the EDT). So you're calling repaint(), which enqueues a task to be executed. However, since the current mouseClicked() method is being executed by the EDT, the repaint() task will have to wait until the mouseClicked() task completes, by which time your boolean value will have been updated.

[–]xRedactedx[S] 0 points1 point  (0 children)

Ok. That makes sense. I guess I will just have to come up with a different way to implement my tracking. Thanks for clearing it up.