Canvas Javafx against the panel

I am a beginner Java / JavaFX programmer, and I am developing a simple JavaFX building design tool where you can pull walls, floors, etc. Thus, objects (mainly lines, circles, polygons, rectangles) are created and created on the screen, and not created before launch.

I am currently using a simple panel as a visual drawing area and add objects directly to the panel, which works quite well. I came across several examples when people implement on a canvas, not in a panel, but I can’t understand what the real difference between the two is or why the panel is not enough.

I was wondering if there are any advantages to using Canvas as my visual area, and not just a panel?

Thank!

+4
source share
1 answer

Canvas gives you more flexibility than a panel. Also, if you need performance, you should use the canvas. With panel and javafx nodes, about 1000 nodes (depending on node, cpu, etc.) The performance impact can be noticeable. Then again e. d. Managing the mouse is easier if you use a panel with nodes on it. You always have borders, while with the canvas you must also maintain the associated dimensions. It all depends on what you want to achieve.

Other than that, since you're new, I suggest you stick with the panel.

+3
source

All Articles