2015-05-16 16 views
1

當您在旋轉的節點上應用DropShadow時,DropShadow隨之旋轉。有沒有簡單的方法來保持DropShadow角度,例如, G。即使在節點旋轉的時候也是右下角?如何在節點旋轉時保持DropShadow的角度

我知道,如果我把所有的節點放到一個組中,並在組上應用陰影,它會工作,但不幸的是這不是我的情況下的選項。

樣品圖片:

  • 有陰影左矩形
  • 具有相同的陰影權矩形,而是180度

enter image description here

你看旋轉,它看起來錯誤陰影方向相反。

代碼

public class HelloEffects extends Application { 

    Stage stage; 
    Scene scene; 

    @Override 
    public void start(Stage stage) { 

     Group group = new Group(); 

     DropShadow ds1 = new DropShadow(); 
     ds1.setOffsetY(4.0f); 
     ds1.setOffsetX(4.0f); 
     ds1.setColor(Color.BLACK); 

     Rectangle rect1 = new Rectangle(100, 200); 
     rect1.relocate(100, 100); 
     rect1.setEffect(ds1); 
     rect1.setFill(Color.RED); 

     Rectangle rect2 = new Rectangle(100, 200); 
     rect2.relocate(300, 100); 
     rect2.setEffect(ds1); 
     rect2.setFill(Color.RED); 
     rect2.setRotate(180); 

     group.getChildren().addAll(rect1, rect2); 

     scene = new Scene(group, 840, 680); 

     stage.setScene(scene); 
     stage.show(); 

    } 

    public static void main(String[] args) { 
     Application.launch(args); 
    } 
} 
+0

我不知道這是可能的,因爲應用'Effect'和'Rotation'不會改變相對界限,而是改變界限,所以除非你撤消那個 - 那意味着沒有旋轉,我的客人將會是你的解決方案。這是我的理解 – Elltz

回答

1

您應該添加一個容器RECT2和應用在容器上的效果,容器可以是面板或組:

Group rect2Container = new Group(rect2); 
rect2Container.setEffect(ds1); 
group.getChildren().addAll(rect1, rect2Container); 
+0

從來沒有想過這會很容易。輝煌! –