Most texts urge me to call super.paintComponent() in the derived class. Is
there a compelling reason for that or can I rely on the proper execution of
the following class hierarchy?
class MyFirstComponent extends javax.swing.JComponent
{
public void paintComponent(java.awt.Graphics a)
{
super.paintComponent(a);
}
}
class MySecondComponent extends MyFirstComponent
{
public void paintComponent(java.awt.Graphics a)
{
// super.paintComponent(a);
// skipping super.paintComponent() here.
// Is that safe?
}
}
> Most texts urge me to call super.paintComponent() in the derived class. Is
> there a compelling reason for that or can I rely on the proper execution of
[quoted text clipped - 17 lines]
> }
> }
The API docs are a primary reference that you should consult regarding
questions such as this. (I.e. those that bear on class / method
contracts.) In this case the API docs of JComponent note: "Further, if
you do not invoker super's implementation you must honor the opaque
property, that is if this component is opaque, you must completely fill
in the background in a non-opaque color. If you do not honor the opaque
property you will likely see visual artifacts." I take this to mean
that no, it is not imperative that you invoke super.paintComponent(), at
least when the superclass is JComponent. You should consider, however,
that paintComponent() may perform some work that you really want to have
done, especially for superclasses other than JComponent itself. Unless
you know *exactly* why you want to avoid invoking the superclass's
version, and exactly what the effect will be, my advice would be to do
as the texts tell you.

Signature
John Bollinger
jobollin@indiana.edu