File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Swing re-paint issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Swing re-paint issue" Watch "Swing re-paint issue" New topic

Swing re-paint issue

Mike Southgate
Ranch Hand

Joined: Jul 18, 2003
Posts: 183
I have a Jtree which allows me to select different nodes. Based on the level of the selected node, I display a different panel on the right of the tree. This works except for one thing. When I switch back and forth it stops painting the panel correctly. It doesn't show up until you move the mouse over some of the components when they suddenly appear.

Here's what I'm doing:

In short, I remove the panel from the parent, add the new one, and then validate.

Any suggestions?


ms<br />SCJP, SCJD
Mike Southgate
Ranch Hand

Joined: Jul 18, 2003
Posts: 183
Well, I seem to have solved this myself, though I'd like to understand why the solution is required...

Adding a call to repaint() seems to solve the problem. But why is an explicit call to repaint required? What are the criteria which indicate a repaint is required?

Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
How Swing Components Are Displayed
I agree. Here's the link:
subject: Swing re-paint issue
Similar Threads
problem in GridBagConstraints.fill
JScrollPane Weight Shift In GridBagLayout
java applet redirect fails
JTable column widths
GridBagLayout positioning