简体   繁体   中英

Full screen JFrame doesn't cover screen

I have searched for a solution to this but can't seem to find it.
If this has already been answered please link me to the answer. I am creating a JFrame setting it to full screen and changing the display mode.
This all works fine and the display mode is supported by my graphics card (I have already checked) so that is all ok. I am adding a canvas to the JFrame, creating a buffer strategy and using it to draw custom graphics to the screen. The issue is that when the display mode changes and the JFrame enters full screen mode it doesn't cover the full screen. This doesn't make sense as the display mode is 1024 x 768 and the canvas size is also 1024 x 768.
Instead the canvas sits in the top left corner of the screen in the same proportions as when the display mode wasn't changed. Furthermore, the graphics the don't draw properly. Everything works fine when I don't try to change the display mode and set full screen.

Here are the three lines of code that sets everything to full screen.

gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
    gd.setFullScreenWindow(this);
    gd.setDisplayMode(new DisplayMode(1024,768,32,48));

I am running windows 10 and my normal display mode is 3840x2160. Here is a screenshot of what happens when I run the code.

屏幕截图

Although it doesnt look like it the display mode definitely changes as the screen goes black and then the screen becomes smaller and more blured.

Have you tried to maximize the window using setExtendedState? (Like in below example)

import javax.swing.JFrame;

public class MaximizedFrame
{
  public static void main(String[] args)
  {
    JFrame frame = new JFrame("My Frame");
    frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
    frame.setVisible(true);
  }
}

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