> 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
[quoted text clipped - 4 lines]
>
> Michael
<http://java.sun.com/products/jfc/tsc/articles/painting/index.html#callbacks>
<http://java.sun.com/products/jfc/tsc/articles/painting/index.html>
On Sat, 15 Mar 2008 13:44:34 -0700 (PDT), travel2light
<everything2light@yahoo.co.uk> 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.

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
Daniel Pitts - 27 Mar 2008 18:13 GMT
> On Sat, 15 Mar 2008 13:44:34 -0700 (PDT), travel2light
> <everything2light@yahoo.co.uk> wrote, quoted or indirectly quoted
[quoted text clipped - 16 lines]
> did that, I could not understand what the new scheme bought them.
> I just use it.
paint in JComponent is designed to call paintComponent and paintBorder,
and handle delegation to the PLAF, as well as handle double buffering.
If you override "paint" you basically create a "heavy-weight" AWT
component rather than a "light-weight" Swing component.

Signature
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>