Java Swing JFrame set fullscreen

w‮al.ww‬utturi.com
Java Swing JFrame set fullscreen
/**
 * @author L a u tturi.com
 * Java Swing Example: set swing jframe fullscreen 
 */
import java.awt.Color;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class Lautturi {
	public static void main(String[] args) {
		JFrame frame = new JFrame("Java Swing - lautturi");

		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setSize(500, 300);
		frame.setLocationRelativeTo(null);
		
		JLabel title = new JLabel("set jframe fullscreen", JLabel.CENTER);
		title.setForeground(Color.red);
		frame.add(title);
		
		frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
		frame.setVisible(true);
	}
}

OR

/**
 * @author L a u tturi.com
 * Java Swing Example: Java Swing program fullscreen
 */
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import javax.swing.JFrame;

public class Lautturi {
	public static void main(String[] args) {
		GraphicsEnvironment graphics = 
				GraphicsEnvironment.getLocalGraphicsEnvironment();
		        
		GraphicsDevice device = graphics.getDefaultScreenDevice();
		JFrame frame = new JFrame("Set JFrame Fullscreen");
		device.setFullScreenWindow(frame);
	}
}
Created Time:2017-10-08 21:37:29  Author:lautturi