Skip to content
Advertisement

Making a JFrame with a JMenuBar open in fullscreen

I have a JFrame that I want to add a menu bar to and then have that JFrame automatically open in fullscreen. If I just make a JFrame and set it to fullscreen with f.setExtendedState(f.getExtendedState()|JFrame.MAXIMIZED_BOTH ); that works fine:

JavaScript

However, once I add a JMenuBar to that JFrame it will no longer open in fullscreen:

JavaScript

What could be the cause for this?

Update:

Switching to JDK11 solved the problem. I was on 15 before and also tried 14, both had the problem.

Advertisement

Answer

once I add a JMenuBar to that JFrame it will no longer open in fullscreen:

Appears in full screen for me. I use JDK11 in Windows 10.

However, the menu doesn’t work because you have a coding problem. You need to add the JMenu to the JMenubar.

JavaScript

Also, I’ve always just used:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement