4 Replies - 7282 Views - Last Post: 11 August 2010 - 08:23 PM Rate Topic: -----

#1 bcranger  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 252
  • View blog
  • Posts: 1,199
  • Joined: 01-February 10

Canvas v. JPanel

Posted 11 August 2010 - 04:30 PM

Well, most people do their drawing for Swing apps on a JPanel, but I was wondering if there is any difference between using a Canvas and JPanel to do the drawing in terms of advantages/disadvantages, if any.

I have heard that Canvas is supposed to be for AWT, not Swing, is that right?
Is This A Good Question/Topic? 0
  • +

Replies To: Canvas v. JPanel

#2 cfoley  Icon User is offline

  • Cabbage
  • member icon

Reputation: 1940
  • View blog
  • Posts: 4,030
  • Joined: 11-December 07

Re: Canvas v. JPanel

Posted 11 August 2010 - 04:44 PM

Canvas is awt and jpanel is swing. However, Swing is built on top of awt so you can use awt in swing applications.

If you need a buffer strategy you meed to use a canvas. However, my feelings are you should be using JPanel unless this is necessary.
Was This Post Helpful? 1
  • +
  • -

#3 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10397
  • View blog
  • Posts: 38,479
  • Joined: 27-December 08

Re: Canvas v. JPanel

Posted 11 August 2010 - 07:36 PM

Canvas is the most efficient component for painting, and it is double-buffered. There is a reason Sun never made a JCanvas. Unless you are doing heavy-duty painting, you should be fine with a normal JPanel.
Was This Post Helpful? 1
  • +
  • -

#4 bcranger  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 252
  • View blog
  • Posts: 1,199
  • Joined: 01-February 10

Re: Canvas v. JPanel

Posted 11 August 2010 - 07:52 PM

Alrighty, I'll keep those facts in mind, thanks!
Was This Post Helpful? 0
  • +
  • -

#5 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8325
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Canvas v. JPanel

Posted 11 August 2010 - 08:23 PM

If you are doing your own painting and not using Layout
If you are not using any JComponent (button, label, textfield, comboBox,...)
use Canvas
else use JPanel
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1