Javafx animation speed

Is there a way to set the animation speed called? I could not find anything. There are actually two questions. First: Animation of the extension is faster than the extension of the content itself. You see that the circle is a bit slower than the strip with the second called paintball.

Secondly: How to change the speed of both of them. I need them at the same speed, because it looks weird.

Here is a small example for testing: batch test;

import javafx.application.Application; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.scene.Scene; import javafx.scene.control.TitledPane; import javafx.scene.layout.VBox; import javafx.scene.shape.Circle; import javafx.scene.shape.Line; import javafx.stage.Stage; public class TestClass extends Application{ public static void main(String[] args) { launch(args); } @Override public void start(Stage primaryStage) throws Exception { VBox vb = new VBox(); { TitledPane tp = new TitledPane(); System.out.println(tp.getContextMenu()); tp.setContent(new Circle(100)); tp.setText("asfadf"); tp.expandedProperty().addListener(new ChangeListener<Boolean>() { @Override public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) { System.out.println("expand " + newValue); } }); vb.getChildren().add(tp); } vb.getChildren().add(new Line(0, 0, 100, 0)); { TitledPane tp = new TitledPane(); tp.setContent(new Circle(100)); tp.setText("asfadf"); tp.expandedProperty().addListener(new ChangeListener<Boolean>() { @Override public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) { System.out.println("expand " + newValue); } }); vb.getChildren().add(tp); } vb.setStyle("-fx-background-color: gray"); Scene scene = new Scene(vb,500,500); primaryStage.setScene(scene); primaryStage.show(); } } 
+5
source share
2 answers

Short answer: there is no API for changing the duration.

However, there are two ways to achieve this:

Alternative # 1: Reflection

Duration is defined in the static final field com.sun.javafx.scene.control.TitledPaneSkin.TRANSITION_DURATION . Using reflection, you can change its value , but it is really bad. . Not only because it is a dirty hack, but also because TitledPaneSkin is an Oracle internal API that can be changed . In addition, this does not fix the problem with different speeds:

  private static void setTitledPaneDuration(Duration duration) throws NoSuchFieldException, IllegalAccessException { Field durationField = TitledPaneSkin.class.getField("TRANSITION_DURATION"); Field modifiersField = Field.class.getDeclaredField("modifiers"); modifiersField.setAccessible(true); modifiersField.setInt(durationField, durationField.getModifiers() & ~Modifier.FINAL); durationField.setAccessible(true); durationField.set(TitledPaneSkin.class, duration); } 

Alternative number 2: set your own skin

To be safe, you can create and use your own skin (start by copying an existing one) using titledPane.setSkin() . This way you can also fix different speeds, which is mainly caused by linear or simple interpolation, but this is pretty good job.

+1
source

I am adding an answer because I do not have enough reputation to leave a comment.

As of 2019-06-12, there is an open jdk issue open at https://bugs.openjdk.java.net/browse/JDK-8225574.

Will continue to monitor this ..

0
source

Source: https://habr.com/ru/post/1234351/


All Articles