Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javafx canvas vs pane

I'm a novice Java/JavaFX programmer and I'm developing a simple JavaFX building design tool where you can draw out walls, floors etc. So objects (mostly Lines, Circles, Polygons, Rectangles images) are drawn & created on screen rather than created prior to run.

I'm currently using a simple Pane as my visual drawing area, and adding objects directly to the pane which is working quite well. I have come across a few examples where people are implementing in a Canvas rather than a Pane but I can't seem to understand what the real difference is between the two or why a Pane doesn't suffice.

I was wondering if there were any benefits to using a Canvas as my visual area rather than just a simple Pane?

Thanks!

like image 253
Nick B Avatar asked Jun 14 '16 04:06

Nick B


1 Answers

A canvas gives you more flexibility than a pane. Also, if you need performance, you should use a canvas. With a pane and javafx nodes, around 1000 nodes (depending on the node, cpu, etc) a performance impact may be noticable. Then again e. g. mouse-handling is easier if you are using a pane with nodes on it. You always have the bounds available, whereas with a canvas you have to maintain the bound sizes as well. It all depends on what you want to achieve.

Other than that, since you are a novice, I suggest you stick with the pane.

like image 192
Roland Avatar answered Sep 18 '22 12:09

Roland