Animate splitpane分隔符

ImR*_*ael 2 javafx slide splitpane

我有一个水平分割窗格,我想点击按钮,更改分隔符位置,以便我创建一些"幻灯片"动画.

divider将从0开始(完成左侧)并且在我的点击它将打开直到0.2,当我再次点击时,它将返回到0;

现在我实现了这一点,我只是使用

spane.setdividerPositions(0.2); 
Run Code Online (Sandbox Code Playgroud)

和分频器位置的变化,但我不能设法慢慢地这样做我真的很喜欢改变分频器位置时的滑动感觉.

谁能帮助我?我在谷歌上发现的所有例子都显示了一些DoubleTransition,但在java 8中不再存在,至少我没有导入.

Jam*_*s_D 5

你可以打电话getDividers().get(0)来获得第一个分频器.它有一个positionProperty()你可以使用时间轴动画:

import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.beans.binding.Bindings;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.SplitPane;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
import javafx.util.Duration;

public class AnimatedSplitPane extends Application {

    @Override
    public void start(Stage primaryStage) {
        SplitPane splitPane = new SplitPane(new Pane(), new Pane());
        splitPane.setDividerPositions(0);

        BooleanProperty collapsed = new SimpleBooleanProperty();
        collapsed.bind(splitPane.getDividers().get(0).positionProperty().isEqualTo(0, 0.01));

        Button button = new Button();
        button.textProperty().bind(Bindings.when(collapsed).then("Expand").otherwise("Collapse"));

        button.setOnAction(e -> {
            double target = collapsed.get() ? 0.2 : 0.0 ;
            KeyValue keyValue = new KeyValue(splitPane.getDividers().get(0).positionProperty(), target);
            Timeline timeline = new Timeline(new KeyFrame(Duration.millis(500), keyValue));
            timeline.play();
        });

        HBox controls = new HBox(button);
        controls.setAlignment(Pos.CENTER);
        controls.setPadding(new Insets(5));
        BorderPane root = new BorderPane(splitPane);
        root.setBottom(controls);
        Scene scene = new Scene(root, 600, 600);
        primaryStage.setScene(scene);
        primaryStage.show();

    }

    public static void main(String[] args) {
        launch(args);
    }
}
Run Code Online (Sandbox Code Playgroud)