JavaFX Canvas vs. Node + Binding

I have a use case where I need to draw a component consisting of about 100 lines and up to 1000 other elements (mostly rectangles and text).

The content of the component should change when the parent node changes its size (for example, when the application window changes its size).

I can think of two approaches to deal with this:

  • Use JavaFX Line, Text, Rectange, etc. Nodes and bind the widths and heights to the parent Node.
  • As in 1. but instead of anchor, create a panel that arranges the elements appropriately.
  • Use the Canvas node and paint like Graphics2D in Swing.

Which approach will be faster? How big is the impact of using bindings to resize this number of nodes?

Is it possible using Node + Binding method to keep the strings clear? AFAIK the lines have to be drawn with a subpixel for legibility, so 0.5px needs to be added to the position. But is it possible to do this conditionally in a binding? I've already tested adding 20 lines to the panel and binding their y-position to the parent's height, but some are drawn crisp and some are blurry.

If creating a new container that layout its children (like VBox, etc.) is the best option, how difficult would the task be?

+3


source to share





All Articles