Answers

Question and Answer:

  Home  Java GUI Framework

⟩ What is the equivalent of AWTs Canvas in Swing?

JPanel, if you want to have a "complete" component with a UI delegate which handles opaque settings (if paintComponent() is correctly overridden).

JComponent if you intend to always draw every pixel in the area of the component (and break the opaque attribute API contract). If you need to have your own special key and mouse processing, you might also want to start with JComponent and create your own UI delegate.

You could even start higher up in the inheritance chain. java.awt.Component is lightweight since Java 1.1. However, you will not get Swing additions like double-buffering.

If this is all Greek to you, use JPanel. And remember, if you use JComponent or JPanel, override paintComponent(), not paint().

 151 views

More Questions for you: