Summary
JWindow
の透明度をTimer
を使用して変更し、フェードアウトで非表示化するよう設定します。
Screenshot

Advertisement
Source Code Examples
JWindow window = new JWindow();
GraphicsConfiguration gc = window.getGraphicsConfiguration();
if (gc != null && gc.isTranslucencyCapable()) {
window.setBackground(new Color(0x0, true));
}
AtomicInteger alpha = new AtomicInteger(100);
Timer animator = new Timer(50, null);
animator.addActionListener(e -> {
int a = alpha.addAndGet(-10);
if (a < 0) {
window.dispose();
animator.stop();
log.append("JWindow.dispose()\n");
} else {
float opacity = a / 100f;
window.setOpacity(opacity);
log.append(String.format("JWindow.setOpacity(%f)%n", opacity));
}
});
Shape shape = new RoundRectangle2D.Float(0f, 0f, 240f, 64f, 32f, 32f);
window.getContentPane().add(makePanel(shape, animator));
window.pack();
window.setLocationRelativeTo(c.getRootPane());
window.setVisible(true);
View in GitHub: Java, KotlinExplanation
JWindow
の背景色にWindow#setBackground(...)
でnew Color(0x0, true)
を設定して透明化JWindow#getContentPane()
で取得したコンテンツペインに半透明の図形を描画するJPanel
を追加JPanel
には背景のみ透明なアイコンと親JWindow
を閉じるJButton
を追加
JButton
がクリックされたらTimer
を起動してJWindow#setOpacity(float)
でウィンドウの不透明性を設定- このウィンドウの不透明性設定はウィンドウ背景色のアルファ成分とは異なり子コンポーネントを含めて適用される
- Window#setOpacity(float) (Java Platform SE 8)