Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Canvas vs. Panel [closed]

If I want to display ellipses and rectangles on a screen, should I use a canvas or a JPanel?

What is the difference? When do I use each?

like image 919
Anonymous181 Avatar asked Apr 22 '26 11:04

Anonymous181


1 Answers

Canvas is an AWT object; JPanel is a lightweight Java Swing object. If you have a Java Swing GUI, I'd strongly recommend using JPanel.

Here's a good link on JPanel:

In the simplest case, you use a JPanel exactly the same way as you would a Panel. Allocate it, drop components in it, then add the JPanel to some Container. However, JPanel also acts as a replacement for Canvas (there is no JCanvas)...

like image 182
paulsm4 Avatar answered Apr 24 '26 23:04

paulsm4