且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

通过在 javafx 2 中拖动来移动节点的正确方法?

更新时间:2023-09-19 22:54:22

您描述的延迟(鼠标和拖动形状之间)是一个已知的 JavaFX 错误:

The lag that you're describing (between your mouse and the dragged shape) is a known JavaFX bug:

https://bugs.openjdk.java.net/browse/JDK-8087922

您可以使用未记录的 JVM 标志来解决它(至少在 Windows 上):

You can work around it (on Windows, at least) by using an undocumented JVM flag:

-Djavafx.animation.fullspeed=true

这个标志通常用于内部性能测试,这就是它没有记录的原因,但我们已经使用它几个月了,到目前为止还没有遇到任何问题.

This flag is normally for internal performance testing, which is why it is undocumented, but we've been using it for months and haven't had any problems with it so far.

还有另一种类似的方法可以解决此错误,该方法可能更容易降低 CPU 使用率.只需关闭 Prism 的垂直同步:

There's another, similar way to workaround this bug that might be a little easier on CPU usage. Simply turn off Prism's vertical sync:

-Dprism.vsync=false

在我们的应用中,这些变通方法中的任何一个都可以解决延迟问题;没有必要两者都做.

In our app, either of these workarounds solves the lag; there's no need to do both.