File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Java Graphics Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Java Graphics" Watch "Java Graphics" New topic

Java Graphics

Ramesh Pramuditha Rathnayake
Ranch Hand

Joined: Oct 31, 2012
Posts: 169

When doing a painting in a JPanel, why we override paintComponent(Graphics g) method other than paint(Graphics g) method..??
What will happen if paint method has overriden...?

Maxim Karvonen
Ranch Hand

Joined: Jun 14, 2013
Posts: 101
Hi, Ramesh.

JComponent paints border and inner components in it's paint method. If you override paint method in a JComponent then some content may appear to be missing.

Also read the Painting in AWT and Swing article. It describes when and which methods are called (including paint and paintComponent).
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2155
Swing is different from AWT when it comes to painting.

You can also look at the Swing tutorial on Custom Painting for an explanation and painting examples.
I agree. Here's the link:
subject: Java Graphics
Similar Threads
How to invoke a paint method in Frame?
The way to accumulate drawn objects on the screen is to
Logos or Pics for JPanel
applet flicker upon netscape wndw resize
paint won't call graphics