简体   繁体   English

全屏缩放

[英]Full screen scaling

I've got a JFrame object which is 1280 by 768 (i may change it to 1024 by 768 in the future).. 我有一个JFrame对象,它是1280 x 768(将来可能会更改为1024 x 768)。

I am making the window full screen by calling this line of code: 我通过调用以下代码行使窗口全屏显示:

GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(window);

(While 'window' is my JFrame object) (虽然“窗口”是我的JFrame对象)

I could see that the screen appears to be fullscreen, which is works very good for me, but if i'll draw a string just like that: 我可以看到屏幕似乎是全屏的,这对我来说非常有用,但是如果我像这样画一个字符串:

g.drawString("Test!!!",100,100);

I could still see that the window is not scaled to the resolution of the JFrame.. (because the string is drawn on the 100x100 point of my screen which is 1920x1080) 我仍然可以看到窗口没有缩放到JFrame的分辨率。。(因为字符串是在屏幕的100x100点上绘制的,即1920x1080)

I have also tried using a new display mode: 我也尝试过使用新的显示模式:

DisplayMode display = new DisplayMode(1280, 768, 16, DisplayMode.REFRESH_RATE_UNKNOWN);
GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setDisplayMode(display);

But i keep getting UnsupportedOperationException: 但是我不断收到UnsupportedOperationException:

Exception in thread "Thread-2" java.lang.UnsupportedOperationException: Cannot change display mode 线程“ Thread-2”中的异常java.lang.UnsupportedOperationException:无法更改显示模式

What is that? 那是什么? is my monitor not supporting changing display mode? 我的显示器不支持更改显示模式吗? or it is just a wrong way of doing that?.. 还是这样做是错误的方式?

My suggestion is, don't use Method Chan. 我的建议是,不要使用方法陈。 It is much much easier to debug your code if you don't use it. 如果不使用它,调试代码要容易得多。

In the official docs of Oracle you will find the right way. Oracle的官方文档中,您将找到正确的方法。 The key part of solving your problem is that you have to set the window full screen mode on before you set the display mode. 解决问题的关键部分是必须在设置显示模式之前将窗口全屏模式设置为打开。 That's the way to unlock the display mode for changes and give exclusive rights to your program. 这样便可以解锁显示模式以进行更改,并为程序提供专有权限。 Just call setFullScreenWindow() before setting the display mode. 只需在设置显示模式之前调用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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM