0

How do I can "slide" the text in a label to the left side? I want to place a "News text" in one line , with short sentences, almost like in news channels in the bottom of screen.

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

Haven't tried anything, I really don't know where start to try it.

camickr
  • 321,443
  • 19
  • 166
  • 288
Iagothz
  • 21
  • 3
  • For something really basic check out: https://stackoverflow.com/a/33907282/131872. For something more complicated check out the [Marquee Panel](https://tips4java.wordpress.com/2011/04/24/marquee-panel/) – camickr Jul 05 '23 at 20:05

2 Answers2

1

Thanks to "camickr", answered in comments.

I've used a funcion mentioned in one of these links, following:

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();
Iagothz
  • 21
  • 3
0

Start by sharing exact code or at least framework or classes you are using.

Click into them, what methods they have.

Is it Swing, SWT or Android?

There is no universal answer.

BTW, you can also can change text of you text label, removing left char every nnn miliseconds.

Good luck

Paul Verest
  • 60,022
  • 51
  • 208
  • 332