I have a Path
in JavaFX that has a set of MoveTo
. I am adding the Path
to a Pane
. Since a Path
is a Node
, it should draw itself automatically, right? The Pane
says it has the Path
as a child, but it is not drawing itself. What am I missing here?
Asked
Active
Viewed 7,825 times
1

goodcow
- 4,495
- 6
- 33
- 52
-
Post an [SSCCE](http://sscce.org) – James_D May 01 '14 at 22:12
1 Answers
5
The Path
consists of the collection of PathElements. MoveTo
is one of them but it moves the starting point of current path, you can make an analogy with mouse cursor like on drawing applications. First you move the mouse cursor to desired place and start drawing by mouse clicking or dragging. To start drawing with Path
, use other path elements, for instance LineTo
.
Path path = new Path();
// First move to starting point
MoveTo moveTo = new MoveTo();
moveTo.setX(100.0f);
moveTo.setY(50.0f);
// Then start drawing a line
LineTo lineTo = new LineTo();
lineTo.setX(75.0f);
lineTo.setY(255.0f);
path.getElements().add(moveTo);
path.getElements().add(lineTo);
For some interesting demo see Draw a semi ring - JavaFX.