Is repainting atomic?
Hello all,
I've got a few general questions regarding repainting. These are to do with a bug I've been assigned at work. I've been sent an image where a button has a half red half green background. This is a standard JButton and background changes are made through setBackground(Color)
calls. The scenario that surrounds this is like so:
1. Button green.
2. A message gets pushed to the client app (non-EDT), which does 2 things: makes the button green, and creates a modal dialogue. (All GUI work done on the EDT though).
3. Now we see a modal dialogue to the right of a half green half red button in the parent frame.
My questions are:
1. Is it possible to someway interrupt repainting?
2. How does repainting of components occur? Left-to-right top-to-bottom, or top-to-bottom left-to-right?
3. How can such a thing occur? :)
Things to note:
1. I can't reproduce this problem. (To me this normally spells threading issue).
2. No Exception has been thrown. The logs indicate this.
3. Not that this means a great deal, but I've been programming with Swing for a while now and I've *never* seen anything like this before!
Any comments, questions, answers appreciated!
Thanks,
Muel.
[1290 byte] By [
Muel.a] at [2007-11-26 16:12:24]

# 1
Your scenario says the button starts green and is turned green - is that a typo?
1. Is it possible to someway interrupt repainting?
If it's done correctly on the EDT then generally speaking, no.
2. How does repainting of components occur? Left-to-right top-to-bottom, or top-to-bottom left-to-right?
Depthwise hierarchical traversal. Actual geographic location is irrelevant.
3. How can such a thing occur? :)
Is there any off-screen buffering going on?
Is the button re-rendered half and half or is it repainted when the dialog is moved? (That is to say, is the partially-repainted segment caused by a clipped repaint after a component is displayed partially over the button?)
To me it sounds most likely that the button's properties have been changed without triggering a repaint, and then a clipped repaint has occurred, where the button repaints part of itself using its new properties.
If so, the solution is to fire a repaint() when modifying the button color.
But, of course, without seeing any code, that's a real shot in the dark.
# 2
Hi Itchyscratchy,
Thanks a lot for your reply.
Your scenario says the button starts green and is turned green - is that a typo?
Yes, sorry.
Depthwise hierarchical traversal. Actual geographic location is irrelevant.
I was actually referring to how graphics paints an image. I don't think I was very clear. I'm aware that this depends on Graphics implementation, but do you know how Sun's default implementation (JDK 1.4) works?
Is there any off-screen buffering going on?
There should not be.
Is the button re-rendered half and half or is it repainted when the dialog is moved?
No, there is no clipping before or after.
I'm afraid I can't provide any code for this issue for a couple of reasons:
1. There is a very large amount of code behind it.
2. Licensing forbids it.
I can, however, email/post a clipped image if an email address (or alternative) can be provided.
Thanks again for your help.
Regards,
Muel.
# 3
I think worrying about the way the JDK paints images is barking up the wrong tree, at this stage at least: Chances are the bug's somewhere in your application code. I would try and isolate the problem by reproducing it in a small application which you can post here. Strip things away a piece at a time and you'll find it - maybe :o)
# 4
I think worrying about the way the JDK paints images is barking up the wrong tree.
Hehehe yeah. I wanted to know this because if images are painted left-to-right top-to-bottom, then it has nothing to do with repainting being interrupted. This is because the button's background is "colour-split" vertically. Ie left half green, right half red.
I would try and isolate the problem by reproducing it in a small application which you can post here.
I can't even reproduce the problem using the full app!!
I am starting to think you might be right in your guess about an underlying property being updated without the representative component being repainted...
Cheers for the help!
-Muel
# 5
the button's background is "colour-split" vertically. Ie left half green, right half red
Well, it'd be mightily unusual to blit images in vertical rasters :o)
I can't even reproduce the problem using the full app!!
Heh! Happy days :o)
I am starting to think you might be right in your guess about an underlying property being updated without the representative component being repainted...
Hm, well it's just a wild guess, but it certainly smells like that, combined with a clipping region coming into the equation somewhere. Having said that, if that is the case then I would think it would be fairly easy to reproduce, so I dunno :o(