我正在努力制作一个"自定义形状"由于某种原因,填充没有显示出哪个im假设意味着它没有被关闭。谁知道为什么?
这是我的代码:
Path path = new Path();
path.getElements().add(new MoveTo(0, 0));
path.getElements().add(new LineTo(5, 0));
path.getElements().add(new MoveTo(5, 0));
path.getElements().add(new LineTo(5, 4));
path.getElements().add(new MoveTo(5, 4));
path.getElements().add(new LineTo(15, 4));
path.getElements().add(new MoveTo(15, 4));
path.getElements().add(new LineTo(15, 0));
path.getElements().add(new MoveTo(15, 0));
path.getElements().add(new LineTo(18, 0));
path.getElements().add(new MoveTo(18, 0));
path.getElements().add(new LineTo(18, 4));
path.getElements().add(new MoveTo(18, 4));
path.getElements().add(new LineTo(20, 4));
path.getElements().add(new MoveTo(20, 4));
path.getElements().add(new LineTo(20, 6));
path.getElements().add(new MoveTo(20, 6));
path.getElements().add(new LineTo(0, 6));
path.getElements().add(new MoveTo(0, 6));
path.getElements().add(new LineTo(0, 0));
path.setFill(Color.BLUE);
path.relocate(250, 250);
root.getChildren().add(path);
root.setScaleX(10);
root.setScaleY(10);
stage.setScene(scene);
stage.show();
非常感谢帮助!
答案 0 :(得分:0)
在MoveTo
之后,您不需要LineTo
到同一位置。此外,您应使用ClosePath
关闭路径,而不是添加LineTo
:
path.getElements().addAll(new MoveTo(0, 0),
new LineTo(5, 0),
new LineTo(5, 4),
new LineTo(15, 4),
new LineTo(15, 0),
new LineTo(18, 0),
new LineTo(18, 4),
new LineTo(20, 4),
new LineTo(20, 6),
new LineTo(0, 6),
new ClosePath());