简体   繁体   English

几个小时后,JavaFX时间轴动画断断续续

[英]JavaFX Timeline Animation Stutters after a couple hours

Preface: So I have this, well its not really all that important what the application is, it's a tcp listener that chats it up all day with some hardware. 前言:所以我有这个,它对应用程序的重要性并不是很重要,它是一个tcp侦听器,可以与某些硬件全天聊天。 But it's also got some display stuff going on. 但是它也有一些显示方面的东西。 The display shows different custom nodes in different areas of the screen and at the bottom of the screen is a grid that displays some "stuff" but when there isn't any "stuff" it scrolls some text across the screen. 显示屏在屏幕的不同区域显示了不同的自定义节点,并且在屏幕的底部是一个网格,显示一些“填充”,但是当没有任何“填充”时,它将在屏幕上滚动一些文本。

Question: As I will post in my method that builds the timeline, there is a Text element that transitions from right to left across the screen. 问题:正如我将在构建时间轴的方法中发布的那样,有一个Text元素在屏幕上从右到左过渡。 This is working as expected for the first hour or maybe two, but after a while it becomes progressively more jittery. 在开始的一两个小时中,它可以按预期工作,但是一段时间后,它会变得越来越不稳定。 The TCP listener is still snappy and the threads it spawns don't have any trouble going in and out of the controller and changing the UI but that scrolling text is jumping like 2 inches at a time across the 55" screen it is displaying on. I really need a way to get text to scroll smoothly like it does when I first start up the application for an indefinite amount of time. 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();
    }
}

Here is where I call the thing from, as you can see I've been trying to experiment with it thinking maybe it was a hardware resources issue, but I haven't been able to get it under control. 这就是我所说的东西,正如您所看到的,我一直在尝试进行尝试,认为这可能是硬件资源问题,但我无法对其进行控制。 I'm testing the thing now and it's in a super visible position in the facility I am at. 我现在正在测试它,它在我所在的设备中处于超可见的位置。 Super embarassing 超级尴尬

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;
            }
        }
    }
}

Scrolling Text Picture 滚动文字图片

the answer was the clear method in the pane that it's setting in. the animation needs to be stopped and deleted 答案是要在其设置的窗格中使用clear方法。需要停止并删除动画

don't use pane.clear(); 不要使用pane.clear(); when theres an animation use LowerGrid.getChildren().removeAll(); 如果有动画,请使用LowerGrid.getChildren()。removeAll();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM