• Post Reply Bookmark Topic Watch Topic
  • New Topic

painting

 
Nikos kat
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi , can anyone explain the difference between paint() and
paintComponent() methods in class JComponent
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to the Swing forum for expert consideration...
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The API for paint spells it out:

This method actually delegates the work of painting to three protected methods: paintComponent, paintBorder, and paintChildren. They're called in the order listed to ensure that children appear on top of component itself. Generally speaking, the component and its children should not paint in the insets area allocated to the border. Subclasses can just override this method, as always. A subclass that just wants to specialize the UI (look and feel) delegate's paint method should just override paintComponent.

So paint is the top-level method and it typically invokes paintComponent. If you are deriving from JComponent or JPanel, you typically do the following.
 
Nikos kat
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks very much for that, very helpful
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!