Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2006

Tip: Looking for answers? Try searching our database.

skip super.paintComponent()

Thread view: 
Martijn Mulder - 14 Feb 2006 16:29 GMT
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?
}
}
John C. Bollinger - 15 Feb 2006 03:49 GMT
> 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



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.