0

I'm attempting to implement a Full Screen option in my Java app (user request).

I've tried this:

private void toggleFullScreen() {
dispose();
setUndecorated(true);
setExtendedState(MAXIMIZED_BOTH);
setVisible(true);

}

and this:

private void toggleFullScreen() {
GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();

dispose();
setUndecorated(true);
gd.setFullScreenWindow(this);
setVisible(true);

}

I get the "frame is displayable" error from setUndecorated(), hence the use of dispose() and setVisible(true). However, the result of the above is that the app opens for a split second and then disappears.

Any ideas what might be going wrong?

Happy to link to the source repo if anyone can help.

4
  • For a full screen start with a new JFrame and there should be no problem. dispose should not be used. Maybe rather setVisible(false) - though likely you already tried that. Commented Feb 18 at 12:11
  • @JoopEggen Thanks. Does the new frame need its own class (.java + .form combo), or can it be created on-the-fly from within the starting frame's class? Commented Feb 18 at 12:34
  • No new .java/.form, just new instances. Commented Feb 18 at 13:06
  • @JoopEggen OK, thanks. Whre should those new instances be created? I'm guessing in the starting frame's class? I've posted a full question about this here: stackoverflow.com/questions/79448445/… Commented Feb 18 at 13:41

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.