Get rid of window decorations in fullscreen?

My problem is that I need to be able to toggle back and forth from windowed mode to fullscreen mode. I can do that fine but if I have window decorations enabled ( frame.setUndecorated(fullscreen) ) then the window decorations will still show up in fullscreen mode. And if I don’t have windows decorations enabled then it wont show up in windowed mode.

I tried using the setUndecorated method to change the decorations but that throws and exception saying that the window is still displayable. So then I tried to dispose of the JFrame first and then set it to Undecorated. This seems to work at first but then I get an exception saying that there is no OpenGL context in the current thread…

If anyone could help me I’d greatly appreciate it. Thanks!

From what thread are you manipulating the frame? (changing decoration, disposing, changing to fullscreen, etc)

Make sure you are doing it from the EDT (either from an event callback, or via invokeLater/invokeAndWait).

Also make sure you have all the necessary synchronization in any render thread(s) , so as to not attempt rendering operations while the frame is being manipulated.

Yeah, doing this should work (maybe even try leaving out dispose):

frame.setVisible(false);
frame.dispose();
frame.setUndecorated(true);

Also, make sure that you’re using the latest JDK/JRE, because it may have been a bug in a previous release. But, if that doesn’t work, I’d just create two frames. Then show one, hide the other. Draw to one and don’t draw to the other. Then when you need to switch just change that stuff. It’ll actually be faster than doing dispose and recreating the window again. Here’s a rough example of what I’m thinking:


private boolean fullscreen = true;

public void setWindowed() {
  fullscreen = false;

  destroyOpenGL();
  fullscreenFrame.setVisible(false);
  windowedFrame.setVisible(true);
  createOpenGL(windowedFrame);
}

//windowedFrame
public void display(...) {
  if(fullscreen) {
    return;
  }

  GL gl = drawable.getGL();
  gl.glFlush
  etc.
}

public void setFullscreen() {
  fullscreen = true;

  destroyOpenGL();
  windowedFrame.setVisible(false);
  fullscreenFrame.setVisible(true);
  createOpenGL(fullscreenFrame);
}

//fullscreenFrame
public void display(...) {
  if(!fullscreen) {
    return;
  }

  GL gl = drawable.getGL();
  gl.glFlush
  etc.
}