2

I am looking for a very simple and efficient way to draw arrows in JavaFX 8, what is the best way to achieve that (performance-wise if let's say I'm willing to draw hundreds or thousands of them)?

Arrows

I've heard using a Canvas to draw on it is quite efficient.

However, I do not know whether the best implementation is to go with:

Natalie Perret
  • 8,013
  • 12
  • 66
  • 129

1 Answers1

2

The best method depends on various factors which we don't know so it's difficult to give a clear answer here. I will try to give a few general hints though and you will have to decide yourself if these are applicable to your problem.

For mass drawings using the canvas sounds like a good idea.

Simple lines and rectangles are much faster than paths (also polylines and polygons).

Some line joins/caps are faster than others.

Avoid transparency.

It may be helpfull to consider specialized approaches like, e.g. creating images of your arrows and then just painting these images.

Michael

mipa
  • 10,369
  • 2
  • 16
  • 35
  • Hm, just one more thing that might have been added to the initial post: but do you know if there is also a proper way to add drag and drop support for those arrows (and eventually how it may affect the decision and the general guidelines you gave above)? – Natalie Perret Sep 12 '15 at 08:38
  • What exactly do you mean by drag and drop here. Do you want to select an arrow on your drawing area and move it to some other place or something similar? – mipa Sep 12 '15 at 08:45
  • yes this sort of drag 'n drop with the mouse in order to change the location of one arrow or a group of arrows. – Natalie Perret Sep 12 '15 at 08:54
  • 1
    That makes it even more complicated. Normally you have to redraw everything in such a case but that is probably too time consuming. If your arrows are always small compared to the size of the whole canvas then it might be possible to redraw just a small portion of it around your selected arrow (without this arrow) and show the moving selected arrow as an overlay on top of everything else. But this all depends on your task and is difficult to answer in general. – mipa Sep 12 '15 at 17:11