Swing Repainting components after they are dragged back into view

Posted on 2006-04-26
Medium Priority
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?
Question by:phavardel
  • 5
LVL 86

Expert Comment

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

Author Comment

ID: 16544954
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 Comment

ID: 16544969
BTW, I'm developing for OSX and XP, and this seems to only happen on XP. Mac looks great.
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.


Author Comment

ID: 16544993
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 Comment

ID: 16555381
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 Comment

ID: 16556405
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.

Accepted Solution

GranMod earned 0 total points
ID: 16575710
Closed, 125 points refunded.
The Experts Exchange
Community Support Moderator of all Ages

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses
Course of the Month9 days, 8 hours left to enroll

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question