如果使用 marquee 标签,如何使 JFrame 的标题栏像 HTML 中的 marquee 一样成为 Marquee?
问问题
2642 次
3 回答
2
请不要。
如果您决定这样做,那么显而易见的技术是使用所需文本的子序列来设置标题。我猜想 Unicode 中的各种部分大小的空间可能会让你稍微平滑一些(或者它们可能显示为正方形)。
或者,您可以使窗口 PL&F 装饰(在 Sun/Oracle 实现中不能与本机 PL&F 一起使用)并自己绘制文本。为了看起来不错,您需要将其调整为特定的 PL&F 和配置。
于 2010-03-22T06:25:42.067 回答
1
上帝原谅我下面的代码
如果您希望选取框在加载后直接启动,请将此代码放入您的框架构造函数中:
int delay = 3000;
int period = 50;
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
int spaces=0;
public void run() {
String title="";
for (int j = 0; j < spaces; j++) {
title+= " " ;
}
title+= "Annoying";
Main.this.setTitle(title);
spaces=(spaces+1)%50;
}
}, delay, period);
更新
根据评论,这是另一个使用 swing.Timer 的版本
Timer timer = new Timer(delay,new ActionListener(){
int spaces=0;
public void actionPerformed(ActionEvent e) {
String title="";
for (int j = 0; j < spaces; j++) {
title+= " " ;
}
title+= "Annoying";
Main.this.setTitle(title);
spaces=(spaces+1)%50;
}}
);
timer.start();
此代码仅供学习使用,请勿在实际产品中使用。
于 2010-03-22T13:35:27.757 回答
0
int delay = 0;
int period = 500;
t.scheduleAtFixedRate(new TimerTask(){
String test = " Test marquee";
int i = 0;
public void run(){
titleChanger(test.substring(i, test.length()));
i++;
if(test.length()==i){
i = 0;
}
}
}, delay, period);
Timer t = new Timer();
public void titleChanger(String t){
this.setTitle(t);
}
试试这个,万无一失。并且更容易理解。
于 2013-05-22T08:36:17.630 回答