JFrame in full screen Java

Solution 1:

Add:

frame.setExtendedState(JFrame.MAXIMIZED_BOTH); 
frame.setUndecorated(true);
frame.setVisible(true);

Solution 2:

If you want put your frame in full-screen mode (like a movie in full-screen), check these answers.

  • How can I do full screen in Java on OSX
  • Java setFullScreenWindow() keep on top

The classes java.awt.GraphicsEnvironment and java.awt.GraphicsDevice are used for put an app in full-screen mode on the one screen (the dispositive).

e.g.:

static GraphicsDevice device = GraphicsEnvironment
        .getLocalGraphicsEnvironment().getScreenDevices()[0];

public static void main(String[] args) {

    final JFrame frame = new JFrame("Display Mode");
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    frame.setUndecorated(true);

    JButton btn1 = new JButton("Full-Screen");
    btn1.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            device.setFullScreenWindow(frame);
        }
    });
    JButton btn2 = new JButton("Normal");
    btn2.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            device.setFullScreenWindow(null);
        }
    });

    JPanel panel = new JPanel(new FlowLayout(FlowLayout.CENTER));
    panel.add(btn1);
    panel.add(btn2);
    frame.add(panel);

    frame.pack();
    frame.setVisible(true);

}

Solution 3:

Use setExtendedState(int state), where state would be JFrame.MAXIMIZED_BOTH.