[英]marquee in title bar in JFrame
如果使用marquee标签,如何使JFrame的标题栏像HTML中的选取框一样成为选取框?
请不要
如果您决定这样做,那么显而易见的技术是设置带有所需文本子序列的setTitle。 我猜想Unicode中的各种局部大小的空格可能会让您稍微平滑一些(或者它们可能显示为正方形)。
或者,您可以装饰PL&F窗口(不能与Sun / Oracle实现中的本机PL&F一起使用)并自己绘制文本。 为了看起来不错,您需要将其调整为特定的PL&F和配置。
上帝原谅我以下代码
如果您希望选取框在加载后直接启动,请将以下代码放入框架构造函数中:
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();
该代码仅用于学习目的,请勿在实际产品中使用。
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);
}
试试看,傻瓜。 而且更容易理解。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.