私は自分のコードを見つめていますが、1 つの問題にかなり悩まされています。フェードアウト遷移を行いたいのですが、フェード遷移の実行中に現在のスレッドをブロックしたいのです。したがって、私の試みは、transition.setOnFinished() が呼び出されるまで、スレッドをブロックする CountDownLatch を作成することでした。そこで、latch.countdown() を作成します。要するに、トランジションが常に完全な長さで表示されるようにしたいのです。
私にはかなり簡単に思えましたが... setOnFinished() は呼び出されません。これは、上記の現在のスレッドがカウントダウン ラッチによってブロックされているためです。
この問題を解決するにはどうすればよいですか? 事前にThx。
private void initView() {
Rectangle rect = new Rectangle();
rect.widthProperty().bind(widthProperty());
rect.heightProperty().bind(heightProperty());
rect.setFill(Color.BLACK);
rect.setOpacity(0.8f);
getChildren().add(rect);
MyUiAnimation animator = new MyUiAnimation();
fadeInTransition = animator.getShortFadeInFor(this);
fadeOutTransition = animator.getShortFadeOutFor(this);
fadeOutTransition.setOnFinished(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent arg0) {
Platform.runLater(new Runnable() {
@Override
public void run() {
latch.countDown();
setVisible(false);
}
});
}
});
}
public void hide() {
fadeInTransition.stop();
if (isVisible()) {
latch = new CountDownLatch(1);
fadeOutTransition.playFromStart();
try {
latch.await();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}