代码之家  ›  专栏  ›  技术社区  ›  Iagothz

在标签内滑动文本

  •  0
  • Iagothz  · 技术社区  · 1 年前

    如何将标签中的文本“滑动”到左侧?我想把“新闻文本”放在一行,用短句,就像屏幕底部的新闻频道一样。

    I want the text runs to the left side, like in  this img

    什么都没试过,我真的不知道从哪里开始尝试。

    1 回复  |  直到 1 年前
        1
  •  1
  •   Iagothz    1 年前

    感谢“卡米克”,在评论中回答。

    我在其中一个链接中使用了一个函数,如下所示:

    String horaCorrenteSistema = "";
    SimpleDateFormat horaFormatada = new SimpleDateFormat("HH:mm:ss");
    Date horaAtual = new Date();
    horaCorrenteSistema = horaFormatada.format(horaAtual);
    ActionListener action = new ActionListener() {  
        public void actionPerformed(ActionEvent e) {  
            String oldText = lblNoticia.getText();
    
            // Scroll right to left
            String newText = oldText.substring(1) + oldText.substring(0, 1);
    
            // Scroll left to right
            //int length = oldText.length();
            //String newText = oldText.substring(length-1, length) + oldText.substring(0, length-1);
    
            lblNoticia.setText( newText );
        }  
    };
    Timer timer = new Timer(500, action);
    timer.start();
    
        2
  •  0
  •   Paul Verest    1 年前

    从共享确切的代码开始,或者至少共享您正在使用的框架或类。

    点击他们,他们有什么方法。

    是Swing、SWT还是Android?

    没有普遍的答案。

    顺便说一句,你还可以更改你的文本标签的文本,每分钟删除一个左字符。

    祝你好运