我正在使用swing在java中创建一个应用程序。我有一个字符串数组,我尝试使用html marquee标签从上到下一一滚动所有字符串。但是面板中不支持marquee标签. 我怎样才能实现它。任何人都可以建议我吗?提前致谢
问问题
1512 次
2 回答
1
我不相信 Swing 支持开箱即用的文本滚动。
最近在 Free the Pixel 上发表的这篇博客文章包含一些代码来制作一些漂亮的文本动画。它可能有用。
于 2010-06-11T07:57:09.697 回答
0
你可以通过使用线程编写自己的代码来做到这一点。
类 Marquee 实现 Runnable { Thread t;
Marquee()
{
t = new Thread(this, "Demo Thread");
t.start();
}
public void run()
{
try
{
for(int i = 820; i>0 ;i-=5)
{
marql.setBounds(i,10,130,40);// marql label moves
Thread.sleep(500);
p3.repaint(); //p3 is a panel with layout null
if(i<10)
{
i = 820;
}
}
}
catch(InterruptedException e)
{
System.out.println("Thread Interrupted "+e);
}
}
}
于 2013-04-10T23:20:21.230 回答