[英]Full screen scaling
我有一個JFrame對象,它是1280 x 768(將來可能會更改為1024 x 768)。
我通過調用以下代碼行使窗口全屏顯示:
GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(window);
(雖然“窗口”是我的JFrame對象)
我可以看到屏幕似乎是全屏的,這對我來說非常有用,但是如果我像這樣畫一個字符串:
g.drawString("Test!!!",100,100);
我仍然可以看到窗口沒有縮放到JFrame的分辨率。。(因為字符串是在屏幕的100x100點上繪制的,即1920x1080)
我也嘗試過使用新的顯示模式:
DisplayMode display = new DisplayMode(1280, 768, 16, DisplayMode.REFRESH_RATE_UNKNOWN);
GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setDisplayMode(display);
但是我不斷收到UnsupportedOperationException:
線程“ Thread-2”中的異常java.lang.UnsupportedOperationException:無法更改顯示模式
那是什么? 我的顯示器不支持更改顯示模式嗎? 還是這樣做是錯誤的方式?
我的建議是,不要使用方法陳。 如果不使用它,調試代碼要容易得多。
在Oracle的官方文檔中,您將找到正確的方法。 解決問題的關鍵部分是必須在設置顯示模式之前將窗口全屏模式設置為打開。 這樣便可以解鎖顯示模式以進行更改,並為程序提供專有權限。 只需在設置顯示模式之前調用setFullScreenWindow()。
Frame frame;
DisplayMode newDisplayMode;
GraphicsDevice gd;
// create a Frame, select desired DisplayMode from the list of modes
// returned by gd.getDisplayModes() ...
if (gd.isFullScreenSupported()) {
gd.setFullScreenWindow(frame);
} else {
// proceed in non-full-screen mode
frame.setSize(...);
frame.setLocation(...);
frame.setVisible(true);
}
if (gd.isDisplayChangeSupported()) { // Sometime it does return false, however the Display Change is still possible. So, this checking is not a must.
gd.setFullScreenWindows(frame); // Important!! Call this before setDisplayMode, otherwise you'll got UnsupportedOperationExaption.
gd.setDisplayMode(newDisplayMode);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.