2011-05-27 74 views
3

我目前正在嘗試在Linux中運行Java中的全屏窗口。事情是我實際上可以使JFrame全屏,但如果框架設置爲undecorated,它不能再次返回到原​​始窗口。如果窗戶裝飾好了,我可以回到原來的大小。GraphicsDevice - 不能從全屏幕返回

GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); 
    GraphicsDevice gs = ge.getDefaultScreenDevice(); 
    ... 
    f.setUndecorated(true);//If set Window can't return to original size 
    gs.setFullScreenWindow(f); 

    gs.setFullScreenWindow(null);//Doesn't work! 

任何想法如何解決這個問題?

回答

0

我不認爲你可以可靠地改變未修飾的全屏幕畫面回窗口模式。我建議創建兩個JFrame,一個全屏和另一個窗口。當您想要返回到窗口模式時,將內容窗格添加到窗口框架(這會自動從全屏框架中移除它),例如

windowedFrame.setContentPane(fullScreenFrame.getContentPane()); 
windowedFrame.pack(); 
windowedFrame.setVisible(true); 
fullScreenFrame.dispose(); 
+0

這是一個好主意,但有一個小問題。我正在使用VLCJ並返回到窗口框架使視頻變黑!沒有圖像。 – mundu 2011-05-27 17:07:35

+0

@mundu,我已經看到,當試圖製作一個'JDialog'全屏時,但對於我來說''JFrame''總能正常工作。 – finnw 2011-05-27 19:38:30

+0

我目前使用JFrame和畫布來繪製視頻幀。它們與以下命令同步。 'mediaPlayer = factory.newEmbeddedMediaPlayer(); mediaPlayer.setVideoSurface(factory.newVideoSurface(canvas));' – mundu 2011-05-28 15:39:02

2
changeFrameFullScreenMode(Frame app){ 
    GraphicsDevice gd = GraphicsEnvironment 
    .getLocalGraphicsEnvironment().getDefaultScreenDevice(); 
    if (gd.getFullScreenWindow() == null){ 
    app.dispose(); 
    app.setUndecorated(true); 
    gd.setFullScreenWindow(app); 
    app.setVisible(true); 
    }else{ // back to windowed mode 
    app.dispose(); 
    app.setUndecorated(false); 
    gd.setFullScreenWindow(null); 
    app.setVisible(true); 
    } 
} 
+0

您能否詳細介紹一下這段代碼? – Heskja 2012-10-21 08:38:27