简体   繁体   中英

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)..

I am making the window full screen by calling this line of code:

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

(While 'window' is my JFrame object)

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)

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:

Exception in thread "Thread-2" java.lang.UnsupportedOperationException: Cannot change display mode

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. 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.

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);
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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