Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem painting

 
Derek Boring
Ranch Hand
Posts: 65
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a JFrame that contains a JPanel (tbox), and a JScrollPane (vPort) which displays the contents of another JPanel (view). The problem is when I draw on 'view' tbox does not repaint and the scrollbars on vPort do not repaint, they show whatever is behind the JFrame. The drawing is done in the JFrame's 'paint' event. I've tried calling the 'repaint()' methods for 'tbox' and 'vPort' at the end of the event and the componets repaint, but then it doesn't show what is drawn in view.

When no repaints are called:


When 'tbox.repaint()' is called:


When 'vPort.repaint()' is called:


When both are repainted:
 
Craig Wood
Ranch Hand
Posts: 1535
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The drawing is done in the JFrame's 'paint' event.
This is not the recommended way to draw in a top–level container. Better to use a JPanel or
JComponent that is dedicated to graphic display. Here is an example.
 
Derek Boring
Ranch Hand
Posts: 65
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, that helps alot.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Zero" -

Welcome to the JavaRanch! We don't have many rules around the ranch, but we do have a policy on displayed names... Please adjust your displayed name to meet the JavaRanch Naming Policy. User names cannot be obviously fake and must consist of a first name and a last name.

You can change your user name here.

Thanks! and welcome to the JavaRanch!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic