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);
Description
- 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)