How to open window maximised?

Hi, I want to know how to open the window maximised. Either it would open already maximised, or I could maximise it immediately after it opens. I have the following code from a stackoverflow answer:

com.jogamp.newt.opengl.GLWindow window = (com.jogamp.newt.opengl.GLWindow)(surface.getNative());
window.setResizable(true);
window.setMaximized(true, true);
//get window width and height without window decorations
println(window.getWidth(), window.getHeight());

However, this code crashes the program with this message:

handleDraw() called before finishing

What happens is, the window pops up then immediately closes with the crash. However, removing 'window.setResizable(true);" actually makes the window resize after popping up, but it still crashes.

Hi @turke1034,

simply call it this way. otherwise you will run into multithreading issue as shown above …

Hope that helps…

Cheers
— mnse

void setup() {
  size(500, 500, P2D);
  java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {
      final com.jogamp.newt.opengl.GLWindow window = (com.jogamp.newt.opengl.GLWindow)(surface.getNative());
      window.setResizable(true);
      window.setMaximized(true, true);
    }
  });
}
void draw() {
  background(0, 0, 255);
}
3 Likes

Hi mnse, this solves what was asked for in the question, thank you very much. But there is 1 more thing I would like to achieve which making it so the user can’t resize the window, because I am trying to simulate fullscreen, which is broken in P2D. I removed window.setResizable(true); however it is still resizable. I added surface.setResizable(false); after in setup() but its the same result.

Hi @turke1034,

Okay!? Never ran into issue while using fullScreen(P2D) !? What OS you are working on ?
The setResizable() functionality depends a bit on OS behaviour, resp. underlying windowmanager.
If you want to simulate fullScreen(P2D) you should use undecorated windows, so for this case I would do…

Hope that helps …

Cheers
— mnse

void setup() {
  size(500, 500, P2D);
  java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {
      final com.jogamp.newt.opengl.GLWindow window = (com.jogamp.newt.opengl.GLWindow)(surface.getNative());
      window.setUndecorated(true);
      window.setMaximized(true, true);
    }
  });
}

void draw() {
  background(sin(frameCount/100.)*128+128, 0, cos(frameCount/100.)*128+128);
}
2 Likes

Hi mnse, I am using windows. According to github there is an issue that the windows magnification in settings impacts the behaviour of fullscreen, probably because processing’s method of making a fullscreen display doesn’t account for certain things.

Making the window undecorated is great thanks so much, its exactly the way fullscreen works. Its all I’ve changed for now, but I’ll report if I encounter anything else.