Java Swing How to - Use Fullscreen mode








Question

We would like to know how to use Fullscreen mode.

Answer

import java.awt.Color;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
/* w w  w .  j  a v a  2s.c  om*/
import javax.swing.JFrame;
import javax.swing.JPanel;

public class Main {
  public static void main(String[] args) {
    GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice vc = env.getDefaultScreenDevice();
    JFrame window = new JFrame();
    JPanel comp = new JPanel();
    comp.setBackground(Color.RED);
    window.add(comp);
    window.setUndecorated(true);
    window.setResizable(false);
    vc.setFullScreenWindow(window);
  }
}