We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Swing Repainting components after they are dragged back into view

phavardel
phavardel asked
on
Medium Priority
287 Views
Last Modified: 2009-12-16
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?
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2016

Commented:
Is it only when the window is moved *off* the screen and back again?

Author

Commented:
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.

Author

Commented:
BTW, I'm developing for OSX and XP, and this seems to only happen on XP. Mac looks great.

Author

Commented:
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.

Author

Commented:
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?

Author

Commented:
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.
Commented:
Closed, 125 points refunded.
GranMod
The Experts Exchange
Community Support Moderator of all Ages

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.