Re: To use paint or paintComponent?



On Sat, 15 Mar 2008 13:44:34 -0700 (PDT), travel2light
<everything2light@xxxxxxxxxxx> wrote, quoted or indirectly quoted
someone who said :

Which is the right one to use for Swing components? I have always used
JPanels with a method paint(Graphics g) and then just called that
method using 'repaint()'. But after reading some of the discussions
here I found out that the correct way to go is to use
paintComponent(Graphics g). Why is this? What is the difference
between the two methods? Thanks for any advice.

See http://mindprod.com/jgloss/paintcomponent.html
http://mindprod.com/jgloss/paint.html

Yes, you should use paintComponent. calling super.paintComponent and
using setOpaque replaces the old update/paint mechanism.

You can trace the calls or look at the code in source.zip, but when I
did that, I could not understand what the new scheme bought them.
I just use it.
--

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
.



Relevant Pages

  • Re: ObjectInputStream available() method
    ... is by reading it. ... Roedy Green Canadian Mind Products ...
    (comp.lang.java.programmer)
  • Re: To use paint or paintComponent?
    ... travel2light wrote: ... JPanels with a method paintand then just called that ... But after reading some of the discussions ... Thanks for any advice. ...
    (comp.lang.java.gui)
  • To use paint or paintComponent?
    ... Which is the right one to use for Swing components? ... JPanels with a method paintand then just called that ... But after reading some of the discussions ... Thanks for any advice. ...
    (comp.lang.java.gui)