#how do i fullscreen my jframe?

1 messages · Page 1 of 1 (latest)

manic bobcat
#

i want to set my jframe and jpanel to fullscreen but i cant get it to work. i tried frame.setExtendedState(frame.MAXIMIZED_BOTH);
but it didnt work at all.

steep fossilBOT
#

<@&987246487241105418> please have a look, thanks.

manic bobcat
steep fossilBOT
grim grove
outer brook
manic bobcat
# grim grove https://stackoverflow.com/a/11570414

didnt work and i got this error: ```Exception in thread "main" java.awt.IllegalComponentStateException: The frame is displayable.
at java.desktop/java.awt.Frame.setUndecorated(Frame.java:931)
at MyGame/main.Main.main(Main.java:30)

steep fossilBOT
manic bobcat
outer brook
#

And call window.setVisible(true); just when you wanna show the Frame not right after the new JFrame()

#

I've just test it

outer brook
#
import javax.swing.*;

public class TestSwing {
    public static void main(String... args) {
        
        JFrame window = new JFrame();
        //window.setVisible(true);  // <-------- Don't set it here!
        window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        window.setResizable(false);
        window.setTitle("2D Adventure");

        //Just for test!
        JButton button = new JButton("Test");
        window.add(button);

        window.setExtendedState(window.MAXIMIZED_BOTH);

        //window.pack(); // <-------- Don't use pack!

        window.setLocationRelativeTo(null);        
        window.setVisible(true);
    }
}    

steep fossilBOT