JavaFX-使用Shape.union()后保持形状边框
在使用union函数后,是否有办法保持JavaFX形状上的边框/笔划?例如,下面是我的代码:JavaFX-使用Shape.union()后保持形状边框,java,javafx,shapes,Java,Javafx,Shapes,在使用union函数后,是否有办法保持JavaFX形状上的边框/笔划?例如,下面是我的代码: Shape rect = new Rectangle(150, 150); rect.setFill(Color.WHITE); rect.setStroke(Color.BLACK); rect.setStrokeWidth(4); Line line = new Line(0, 40, 150, 40); line.setStrokeWidth(2); Shape combined = Shap
Shape rect = new Rectangle(150, 150);
rect.setFill(Color.WHITE);
rect.setStroke(Color.BLACK);
rect.setStrokeWidth(4);
Line line = new Line(0, 40, 150, 40);
line.setStrokeWidth(2);
Shape combined = Shape.union(line, rect);
combined.setFill(Color.WHITE);
combined.setStroke(Color.BLACK);
pane.getChildren().add(combined);
预期输出:
实际输出:
我是否可以将这两个元素合并在一起,以便将它们拖放到一起?您的问题是
合并了.setFill(Color.WHITE)代码>,因为它清除了以前所有的形状
更改
试试这样的
Line line = new Line(0, 40, 150, 40);
Shape rect = new Rectangle(150, 150);
Shape combined = Shape.subtract(rect,line);
combined.setFill(Color.WHITE);
combined.setStroke(Color.BLACK);
rect.setFill(Color.WHITE);
rect.setStroke(Color.BLACK);
rect.setStrokeWidth(4);
line.setStrokeWidth(2);
line.setStroke(Color.BLACK);
line.setFill(Color.BLACK);
pane.getChildren().add(combined);
输出将是这样的
有关shape.union、subtract、intersect
go的详细信息,请参见!Shape.substract()而不是Shape.union()适合我。非常感谢。