phavardel
asked on
Swing Repainting components after they are dragged back into view
In a Swing app, I have made a simple component with custom painting that I use as a TreeCellRenderer for non-leaf nodes in a JTree.
However, if you grab the whole app window and drag it so that the tree (or part of it) is off the side of your monitor, when it gets dragged back in, the painting is all screwed up.
I haven't been able to find an event that tells me when a component becomes unviewable like this and when it becomes reviewable. I'd like to be able to attach a listener to such an event and just force a repaint.
Or, if there's a better way, I'm up for that, too.
Any suggestions?
However, if you grab the whole app window and drag it so that the tree (or part of it) is off the side of your monitor, when it gets dragged back in, the painting is all screwed up.
I haven't been able to find an event that tells me when a component becomes unviewable like this and when it becomes reviewable. I'd like to be able to attach a listener to such an event and just force a repaint.
Or, if there's a better way, I'm up for that, too.
Any suggestions?
Is it only when the window is moved *off* the screen and back again?
ASKER
Yes, only when the Jtree is moved off the screen and back. If only part of the Jtree is moved out there, only that part of the components gets mixed up.
ASKER
BTW, I'm developing for OSX and XP, and this seems to only happen on XP. Mac looks great.
ASKER
Right now, so it doesn't irritate me, I have the scrollpane the tree is in listening for ancestorMoved, and repainting on that. But, that's a lot of unneccessary repainting.
ASKER
Alright, correction. It looked like it only happened moving it off the screen and back. It also seems to happen when part of the tree is obscured by another window (either another frame of the same program, or some other windows program). It happens when _part_ of the tree is obscured. If the entire tree is hidden, and then re-displayed (e.x. by clicking the program in the taskbar, or navigating back to it with alt+tab) all at once, it repaints.
The key seems to be that only _part_ of the tree is obscured.
Any ideas?
The key seems to be that only _part_ of the tree is obscured.
Any ideas?
ASKER
Ugh, big stupid mistake.
I was requesting the clipping bounds, but painting as though that were the entire component size. Hence, the mix up, and why it worked when the entire component was hidden and then revealed.
Not sure why it was working on mac before, but, whatever.
I was requesting the clipping bounds, but painting as though that were the entire component size. Hence, the mix up, and why it worked when the entire component was hidden and then revealed.
Not sure why it was working on mac before, but, whatever.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.