[英]JavaFX Timeline Animation Stutters after a couple hours
前言:所以我有这个,它对应用程序的重要性并不是很重要,它是一个tcp侦听器,可以与某些硬件全天聊天。 但是它也有一些显示方面的东西。 显示屏在屏幕的不同区域显示了不同的自定义节点,并且在屏幕的底部是一个网格,显示一些“填充”,但是当没有任何“填充”时,它将在屏幕上滚动一些文本。
问题:正如我将在构建时间轴的方法中发布的那样,有一个Text元素在屏幕上从右到左过渡。 在开始的一两个小时中,它可以按预期工作,但是一段时间后,它会变得越来越不稳定。 TCP侦听器仍然很灵活,它产生的线程在进出控制器和更改UI时都没有任何问题,但是滚动文本在显示的55英寸屏幕上一次跳跃了2英寸。我确实需要一种使文本流畅滚动的方法,就像我无限期地启动应用程序时一样。
private void buildChyron() throws IllegalArgumentException {
setMessages();
LowerGrid.getChildren().clear();
StringBuilder txtstr = new StringBuilder();
for (String s : messages) {
txtstr.append(s).append(" ");
}
txtstr = new StringBuilder(txtstr.toString().trim());
Text msg = new Text(txtstr.toString());
LowerGrid.add(msg, 0, 0);
msg.setTextOrigin(VPos.TOP);
msg.setFont(Font.font("Veranda", FontWeight.BOLD, 150));
double sceneWidth = MainGrid.getWidth();
double msgWidth = msg.getLayoutBounds().getWidth();
KeyValue initKeyValue = new KeyValue(msg.translateXProperty(), sceneWidth);
KeyFrame initFrame = new KeyFrame(Duration.ZERO, initKeyValue);
KeyValue endKeyValue = new KeyValue(msg.translateXProperty(), -1.0 * msgWidth);
KeyFrame endFrame = new KeyFrame(Duration.seconds((msgWidth + sceneWidth) / messageRate), endKeyValue);
if ((timeline != null) && (timeline.getStatus().equals(Timeline.Status.PAUSED))) {
timeline.playFromStart();
} else {
timeline = new Timeline(initFrame, endFrame);
timeline.setCycleCount(Timeline.INDEFINITE);
if (msgIndex == messages.size() - 1) msgIndex = 0;
else msgIndex++;
timeline.playFromStart();
}
}
这就是我所说的东西,正如您所看到的,我一直在尝试进行尝试,认为这可能是硬件资源问题,但我无法对其进行控制。 我现在正在测试它,它在我所在的设备中处于超可见的位置。 超级尴尬
private void updateStack() {
int count = 0;
System.out.println(andonStack);
andonStack.sortStack();
LowerGrid.getChildren().clear();
if (pokeyStack.size() > 0) {
AndonPane pane = new AndonPane(pokeyStack.get(0).getPokayo());
LowerGrid.add(pane, 0, 0, 9, 1);
} else {
int i;
for (i = 0; i < andonStack.size(); i++) {
if (i >= 9) break;
panes[i] = new AndonPane(((AndonSignalStack.AndonSignal) andonStack.get(i)).getType(),
((AndonSignalStack.AndonSignal) andonStack.get(i)).getStation(), this);
count++;
}
for (; i < 9; i++) {
panes[i] = new Pane();
panes[i].setStyle("-fx-background-color: rgba(0,0,0, 0)");
panes[i].setPrefWidth(MainGrid.getWidth() * (9 - i) / 9);
}
for (i = 0; i < count; i++) {
LowerGrid.add(panes[i], i, 0);
}
if (i == 0) {
Platform.runLater(this::buildChyron);
}else{
if (timeline != null) {
System.gc();
timeline.stop();
timeline = null;
}
}
}
}
答案是要在其设置的窗格中使用clear方法。需要停止并删除动画
不要使用pane.clear(); 如果有动画,请使用LowerGrid.getChildren()。removeAll();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.