Swing/SplashScreen のバックアップソース(No.21)
- バックアップ一覧
- 差分 を表示
- 現在との差分 を表示
- 現在との差分 - Visual を表示
- バックアップ を表示
- Swing/SplashScreen へ行く。
- 1 (2004-10-08 (金) 06:25:21)
- 2 (2004-11-04 (木) 10:11:31)
- 3 (2004-11-10 (水) 01:12:08)
- 4 (2005-04-28 (木) 04:33:00)
- 5 (2005-05-11 (水) 23:51:41)
- 6 (2005-09-30 (金) 16:30:03)
- 7 (2006-02-17 (金) 16:09:25)
- 8 (2006-02-27 (月) 16:28:20)
- 9 (2006-03-28 (火) 12:03:11)
- 10 (2006-05-26 (金) 12:47:41)
- 11 (2006-08-17 (木) 11:16:15)
- 12 (2007-05-04 (金) 03:28:38)
- 13 (2007-07-26 (木) 17:14:20)
- 14 (2007-09-25 (火) 18:48:21)
- 15 (2009-11-09 (月) 14:52:38)
- 16 (2011-03-20 (日) 16:55:10)
- 17 (2013-02-26 (火) 14:52:05)
- 18 (2013-04-06 (土) 05:29:38)
- 19 (2013-09-14 (土) 21:14:36)
- 20 (2013-09-15 (日) 01:52:57)
- 21 (2014-12-28 (日) 15:04:58)
- 22 (2016-04-08 (金) 15:19:54)
- 23 (2016-08-26 (金) 14:38:11)
- 24 (2017-10-10 (火) 16:25:51)
- 25 (2018-08-31 (金) 17:48:50)
- 26 (2020-08-27 (木) 18:27:38)
- 27 (2022-02-10 (木) 00:35:54)
- 28 (2024-01-27 (土) 14:26:24)
- 29 (2024-02-02 (金) 11:52:26)
--- title: JWindowを使ったSplash Screenの表示 tags: [JWindow, JLabel] author: aterai pubdate: 2003-10-13 description: JWindowを使って、Splash Screenを表示します。 --- * 概要 [#u76ddf25] `JWindow`を使って、`Splash Screen`を表示します。以下のサンプルコードは、`%JAVA_HOME%/demo/jfc/SwingSet2/src/SwingSet2.java`から引用改変したものです。 #download(https://lh6.googleusercontent.com/_9Z4BYR88imo/TQTTtxuiuuI/AAAAAAAAAk4/JhuyuS80C4M/s800/SplashScreen.png) * サンプルコード [#raad4e3d] #code(link){{ private JWindow splashScreen; private JLabel splashLabel; public MainPanel() { super(); createSplashScreen(SPLASH_PATH); EventQueue.invokeLater(new Runnable() { @Override public void run() { showSplashScreen(); } }); //長い処理のdummy try{ Thread.sleep(3000); }catch(InterruptedException e) { System.out.println(e); } EventQueue.invokeLater(new Runnable() { @Override public void run() { showPanel(); hideSplash(); } }); } public void createSplashScreen(String path) { ImageIcon img = new ImageIcon(getClass().getResource(path)); splashLabel = new JLabel(img); splashScreen = new JWindow(getFrame()); splashScreen.getContentPane().add(splashLabel); splashScreen.pack(); splashScreen.setLocationRelativeTo(null); } public void showSplashScreen() { splashScreen.setVisible(true); } public void hideSplash() { splashScreen.setVisible(false); splashScreen = null; splashLabel = null; } public JFrame getFrame() { return frame; } public void showPanel() { this.setPreferredSize(new Dimension(300, 200)); frame.getContentPane().add(this); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); } }} * 解説 [#j7466f5a] 上記のサンプルコードでは、クラスパスの通った場所にある`/resources/images/splash.png`を読み込んでスプラッシュ・スクリーン(起動画面)を表示しています。`JWindow`の表示、非表示は、イベントディスパッチスレッド(`EDT`)で行われるように、`EventQueue.invokeLater`の中で実行しています。 ---- サンプルの画像は、[http://www.n-generate.com/download.html n-Gen]を使って生成しています。 ---- `Java SE 6`では、起動時にスプラッシュ・スクリーンとして表示する画像をコマンドラインや`manifest.mf`で指定したり、`SplashScreen`オブジェクトを生成して表示することができるようです。 - [http://web.archive.org/web/20090419180550/http://java.sun.com/developer/JDCTechTips/2005/tt1115.html#1 SPLASH SCREENS AND JAVA SE 6] //- [http://java.sun.com/developer/technicalArticles/J2SE/Desktop/javase6/splashscreen/ New Splash-Screen Functionality in Java SE 6] - [http://www.oracle.com/technetwork/articles/javase/splashscreen-135938.html New Splash-Screen Functionality in Java SE 6] * 参考リンク [#l19aa452] - [[JDialogでモーダルなJProgressBar付きSplash Screenを表示する>Swing/ProgressSplashScreen]] * コメント [#gc355cfa] #comment - `Splash Screen`を`Java SE 6`の機能で表示させるために、`splashScreen.setVisible(false)`にしていたテスト版のサンプルが添付されていたのを修正しました。 -- &user(aterai); &new{2007-09-25 (火) 18:56:13}; #comment