JLabelの文字列を点滅させる

編集者:Terai Atsuhiro
作成日:2004-04-12
更新日:2024-04-12 (金) 14:44:59

概要

javax.swing.Timer を使って文字列が点滅するJLabelを作成します。

サンプルコード

javax.swing.Timer timer = new javax.swing.Timer(600, new ActionListener() {
  boolean flg = true;
  public void actionPerformed(ActionEvent e) {
    if(flg) setText("!警告!");
    else    setText("");
    flg = !flg;
  }
});
timer.start();

解説

ラベルのテキストと空文字列を、javax.swing.Timerを使って交互に表示しています。点滅の間隔や、文字列の色を変えたりして実験してみてください。

コメント