开发者

Scrolling Text with Transparent Background

I used to write a Tect Ticker ,but un开发者_StackOverflow社区fortunately im weak on Java and i should make this work on Linux so : I need a JLabel which handles text and that text should move like a News Ticker ,it should scroll the text inside a JPanel from End to Being JPanel Bounds horizontally .

If anyone had this experience than i`ll appreciate sharing with me.

Cheers

Update : I solved the problem by using this example Java Translucent and next using Vincent Ramdhanie example i could Animate it .


Here is an example of a JPanel with a label that uses a simple thread to scroll some text. You can modify it to suit your needs.

 public class Scroller extends JPanel implements Runnable{
  JLabel label;
  String str = "The Message to Scroll ";

  public Scroller(){
    super();
    label = new JLabel(str);
    add(label);
    Thread t = new Thread(this);
    t.start();
  }

  public void run(){
    while(true){
        char c = str.charAt(0);
        String rest = str.substring(1);
        str = rest + c;
        label.setText(str);
        try{
            Thread.sleep(200);
        }catch(InterruptedException e){}
    }
  }
 }

So you can place this on a JFrame to see it in action. Also the the string algorithm may not be optimal but it works.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜