swt 显示滚动字幕

swt 显示滚动字幕
private Label doneLabel;
private Timer timer;

    public class ATask extends TimerTask {
        @Override
        public void run() {
            showScrollText(doneLabel);
           

        }
    }

    /**
     * 滚动显示字幕
     *
     * @param toDoLabel
     */
    private void showScrollText(final Label toDoLabel) {
        if (toDoLabel != null) {
            if (toDoLabel.isDisposed()) {
                timer.cancel();
                return;
            }
            shell.getDisplay().asyncExec(new Runnable() {
                // @Override
                public void run() {
                    String txt = toDoLabel.getText();
                    if (txt != null && txt.length() > 50) {
                        txt = txt.substring(1, txt.length())
                                + txt.substring(0, 1);
                        toDoLabel.setText(txt);
                    }
                }

            });

        }
    }
构造的时候
// 滚动显示字幕
        timer = new Timer();
        timer.schedule(new ATask(), 0, 500);

        //
    }

    // @Override
    public void dispose() {
        timer.cancel();
        super.dispose();
    }
private Timer timer;

    public class ATask extends TimerTask {
        @Override
        public void run() {
            showScrollText(doneLabel);
           

        }
    }


    /**
     * 滚动显示字幕
     *
     * @param toDoLabel
     */
    private void showScrollText(final Label toDoLabel) {
        if (toDoLabel != null) {
            if (toDoLabel.isDisposed()) {
                timer.cancel();
                return;
            }
            shell.getDisplay().asyncExec(new Runnable() {
                // @Override
                public void run() {
                    String txt = toDoLabel.getText();
                    if (txt != null && txt.length() > 50) {
                        txt = txt.substring(1, txt.length())
                                + txt.substring(0, 1);
                        toDoLabel.setText(txt);
                    }
                }

            });

        }
    }


构造的时候
// 滚动显示字幕
        timer = new Timer();
        timer.schedule(new ATask(), 0, 500);

// @Override
    public void dispose() {
        timer.cancel();
        super.dispose();
    }



你可能感兴趣的:(swt 显示滚动字幕)