Swingコンポーネントの強化版
http://java.net/downloads/swingx/releases/
http://itpro.nikkeibp.co.jp/article/COLUMN/20110111/355957/
サンプル
1 |
import org.jdesktop.swingx.*;
import org.jdesktop.swingx.painter.Painter;
import org.jdesktop.swingx.painter.BusyPainter;
import org.jdesktop.swingx.painter.MattePainter;
import java.awt.geom.Ellipse2D;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class BusyLabelSample3 {
private JXBusyLabel label;
private JXPanel glass;
private Timer timer;
public BusyLabelSample3() {
JFrame frame = new JFrame("Busy Label Sample");
frame.setSize(200, 120);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new FlowLayout());
initBusyLabel(frame);
JButton button = new JButton("Start");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
startProcess();
}
});
frame.add(button);
frame.setVisible(true);
}
private void initBusyLabel(JFrame frame) {
// グラスペインに使用するパネル
glass = new JXPanel();
glass.setOpaque(false);
// 背景色を半透明にする
Painter mattePainter
= new MattePainter(new Color(1.0f, 1.0f, 1.0f, 0.7f));
glass.setBackgroundPainter(mattePainter);
// マウスイベントをブロックする
glass.addMouseListener(new MouseAdapter(){});
// ビジーラベル
label = new JXBusyLabel(new Dimension(50, 50));
BusyPainter painter
= new BusyPainter(new Ellipse2D.Float(0.0f, 0.0f, 10.0f, 10.0f),
new Ellipse2D.Float(6.0f, 6.0f, 38.0f, 38.0f));
painter.setTrailLength(8);
painter.setPoints(8);
painter.setBaseColor(new Color(0x00, 0x00, 0x00, 0x00));
painter.setHighlightColor(new Color(0x66, 0xCC, 0xFF, 0xFF));
label.setBusyPainter(painter);
// グラスペインにビジーラベルを貼る
glass.add(label);
// グラスペインをフレームに設定
frame.setGlassPane(glass);
// レイアウト
GridBagLayout layout = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
glass.setLayout(layout);
c.fill = GridBagConstraints.BOTH;
c.gridwidth = GridBagConstraints.REMAINDER;
layout.setConstraints(label, c);
}
private void startProcess() {
// グラスペインを表示
glass.setVisible(true);
// ラベルのアニメーションを開始する
label.setBusy(true);
// 5 秒後、グラスペインを非表示にする
ActionListener task = new ActionListener() {
public void actionPerformed(ActionEvent evt) {
label.setBusy(false);
glass.setVisible(false);
timer.stop();
}
};
timer = new Timer(5000, task);
timer.start();
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new BusyLabelSample3();
}
});
}
} |
[通知用URL]
Tweet
最終更新時間:2011年11月12日 21時35分08秒