JFrame标题栏中的选框

时间:2010-03-22 06:12:50

标签: java swing jframe marquee

如果使用选框标记,如何将JFrame的标题栏设置为Marquee,就像HTML中的选框一样?

3 个答案:

答案 0 :(得分:2)

请不要。

如果你决定,那么显而易见的技巧是使用所需文本的子序列setTitle。我想Unicode中的各种部分大小的空格可能会让你略微平滑(或者它们可能显示为正方形)。

或者,您可以将窗口PL& F修饰(不适用于Sun / Oracle实现中的原生PL& F)并自己绘制文本。为了看起来不错,您需要将其调整到特定的PL& F和配置。

答案 1 :(得分: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();

此代码仅供学习使用,请勿在实际产品中使用。

答案 2 :(得分: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);
}

试试这个,傻瓜证明。而且更容易理解。

相关问题