2017-11-06 14 views
1

ユニオン関数を使用した後で、JavaFXシェイプで枠線/線を維持する方法はありますか?たとえば、ここに私のコードです:JavaFX - Shape.union()を使用した後にシェイプボーダーを維持する

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); 

予想される出力:

Expected Output

実際の出力:

Actual Output

がとにかくあり、私は労働組合ができることを2つ一緒に私はca n一緒にドラッグアンドドロップしますか?

答えて

1

あなたの問題はcombined.setFill(Color.WHITE);です。これはすべて前のshapeの変更がクリアされているためです。

プットアウトこの

 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); 

のようなものがうんhere

+1

を行くshape.union,subtract,intersectについての詳細情報については、この

enter image description here

ことが好きになるでしょうお試しください! Shape.union()の代わりにShape.substract()が私のために働いていました。ありがとうございました! –

関連する問題