2015-01-06 88 views
0

我想在BorderPane的左節點上做一個TranslateTransition。我可以讓節點在點擊時「滑入」,但「滑出」不能按預期工作。這是代碼片段。指揮顛倒TranslateTransition

@Override 
public void initialize(URL url, ResourceBundle rb) { 
    vbx_lfpane.setVisible(false); 
}  

@FXML 
private void paneClicked(MouseEvent event) { 
    if(vbx_lfpane.isVisible()) { 
     vbx_lfpane.setVisible(false); 
     TranslateTransition tt1 = new TranslateTransition(Duration.millis(500), vbx_lfpane); 
     tt1.setFromX(vbx_lfpane.getLayoutBounds().getMinX()); 
     tt1.setToX(- (vbx_lfpane.getLayoutBounds().getMinX() + vbx_lfpane.getWidth())); 
     tt1.play(); 
    } else { 
     vbx_lfpane.setVisible(true); 
     vbx_lfpane.setTranslateX(-vbx_lfpane.getWidth()); 
     TranslateTransition tt2 = new TranslateTransition(Duration.millis(500), vbx_lfpane); 
     tt2.setByX(vbx_lfpane.getWidth()); 
     tt2.play(); 
    } 
} 

回答

1

您在開始的「滑出」過渡之前設置的vbx_lfpanefalse知名度。當轉換完成時,您需要將可見性設置爲false

tt1.setOnFinished(e -> vbx_lfpane.setVisible(false)); 
tt1.play();