Swing/FullScreen のバックアップの現在との差分(No.3)
TITLE:Windowのフルスクリーン化
Windowのフルスクリーン化
Posted by terai at 2008-04-28- category: swing folder: FullScreen title: Windowのフルスクリーン化 tags: [GraphicsEnvironment, JFrame, JDialog] author: aterai pubdate: 2008-04-28T10:19:14+09:00 description: JDialogやJFrameなどを、フルスクリーン表示に切り替えます。 image:
概要
JDialog
やJFrame
などを、フルスクリーン表示に切り替えます。
Screenshot
Advertisement
概要
JDialogやJFrameなどを、フルスクリーン表示に切り替えます。- &jnlp;
- &jar;
- &zip;
#screenshot
サンプルコード
#spanend
#spanadd
* サンプルコード [#sourcecode]
#spanend
#spanadd
#code(link){{
#spanend
private void toggleFullScreenWindow() {
GraphicsEnvironment graphicsEnvironment
= GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice graphicsDevice
= graphicsEnvironment.getDefaultScreenDevice();
if(graphicsDevice.getFullScreenWindow()==null) {
dialog.dispose(); //destroy the native resources
GraphicsEnvironment graphicsEnvironment =
GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice graphicsDevice =
graphicsEnvironment.getDefaultScreenDevice();
if (Objects.isNull(graphicsDevice.getFullScreenWindow())) {
dialog.dispose(); // destroy the native resources
dialog.setUndecorated(true);
dialog.setVisible(true); //rebuilding the native resources
dialog.setVisible(true); // rebuilding the native resources
graphicsDevice.setFullScreenWindow(dialog);
}else{
} else {
graphicsDevice.setFullScreenWindow(null);
dialog.dispose();
dialog.setUndecorated(false);
dialog.setVisible(true);
dialog.repaint();
}
requestFocusInWindow();
}
解説
上記のサンプルは、JDialogをフルスクリーン表示とウィンドウ表示に切り替えることが出来ます。解説
上記のサンプルは、JDialog
をフルスクリーン表示とウィンドウ表示に切り替えることが出来ます。
- F11キー、ダブルクリック
- F11キー、ダブルクリック
- フルスクリーン表示、ウィンドウ表示の切り替え
- ESCキー
- Escキー
- アプリケーション終了
フルスクリーン表示とウィンドウ表示を切り替える前に、タイトルバーの非表示、表示もsetUndecoratedメソッドで切り替えていますが、このメソッドを使用する前に一旦disposeしてウインドウのネイティブリソースを開放しておく必要があります。
- setUndecorated(boolean undecorated)は、ダイアログが表示されていないときにだけ呼び出すことができますが、この表示は isVisible(false)ではなく、isDisplayable()がfalseの意味なので、dialog.setVisible(false); では、 Exception in thread "AWT-EventQueue-0" java.awt.IllegalComponentStateException: The dialog is displayable. が発生します。
- フルスクリーン表示とウィンドウ表示を切り替える前にタイトルバーの非表示、表示も
setUndecorated(...)
メソッドで切り替え- このメソッドを使用する前に一旦
dispose
してウィンドウのネイティブリソースを開放しておく必要がある
- このメソッドを使用する前に一旦
-
setUndecorated(boolean undecorated)
はウィンドウが表示されていない状態の場合のみ呼び出し可能だが、この「表示されていない」はisVisible()
ではなくisDisplayable()
がfalse
の意味なので、dialog.setVisible(false);
のみ実行するとException in thread "AWT-EventQueue-0" java.awt.IllegalComponentStateException: The dialog is displayable.
が発生する
- - Webstart(署名無し)から実行した場合、タスクバー(Windows)などを消してフルスクリーン化は出来ないようです。