标签的JavaFX打字机效果 [英] JavaFX typewriter effect for label

查看:64
本文介绍了标签的JavaFX打字机效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对这种方法有一些疑问.它工作正常,但有一个小问题.我称之为这种方法的时间太少了.因此只有最后一个字符串会打印在标签上.但我希望下一个字符串开始打印,仅在上一个字符串完成之后. 对不起,我的英语((

i have some problem with this method. it works fine, but with one little problem. there is too little time among i call this method. so only the last String is printed on a label. but i want that the next String starting printed, only after previous String is finished. Sorry for my English((

 public void some(final String s) {

    final Animation animation = new Transition() {
        {
            setCycleDuration(Duration.millis(2000));
        }

        protected void interpolate(double frac) {


            final int length = s.length();
            final int n = Math.round(length * (float) frac);
            javafx.application.Platform.runLater(new Runnable() {
                @Override
                public void run() {

                    status.setValue(s.substring(0, n));

                }
            }
            );
        }

    };

    animation.play();

}

推荐答案

使用以下代码获得打字效果.

Use the following code to get a typewriting effect.

public void AnimateText(Label lbl, String descImp) {
    String content = descImp;
    final Animation animation = new Transition() {
        {
            setCycleDuration(Duration.millis(2000));
        }

        protected void interpolate(double frac) {
            final int length = content.length();
            final int n = Math.round(length * (float) frac);
            lbl.setText(content.substring(0, n));
        }
    };
    animation.play();

}

这篇关于标签的JavaFX打字机效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆