Click here to Skip to main content
13,000,742 members (48,367 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


1 bookmarked
Posted 20 Jun 2012

How to Make Frame Full Screen in Java

, 20 Jun 2012
Rate this:
Please Sign up or sign in to vote.
Make your Window full screen


This tip guides you to make a Frame full screen.


To make a frame full screen, first we need to have access to the local screen. The GraphcisEnvironment class contains a method which helps to access the default screen device. Once we get access to the screen, we need a method that helps to set the frame to full screen. For this, we have GraphicsDevice class that contains a method setFullScreen(Window frame). Another class DisplayMode is needed to set the screen size and refresh rate.

Using the Code

First, create a class with name Now create GraphicsDevice reference say vc, in the constructor initialize the vc. Create two methods, one setFullScreen with two parameters DisplayMode and Frame (which you want to be full screen). The other one is CloseFullScreen to get out of the full screen.

import java.awt.*;
import javax.swing.*;

public class FullScreen(){
	GraphicsDevice vc;
	//Initialize the vc with the Screen Device
	public FullScreen(){
		GraphicsEnvironment ge=GraphicsEnvironment.getLocalGraphicsEnvironment();
//Set the Frame to Full Screen
public void setFullScreen(DisplayMode dm, JFrame win){

//Remove the Title Bar, Maximization , Minimization Button...

// Can not be resized

//Make the win(JFrame) Full Screen

 //check low-level display changes are supported for this graphics device.
if(dm!=null && vc.isDisplayChangeSupported()){
        catch(Exception ex){
	//To Exit From Full Screen
	public void CloseFullScreen(){
		Window w=vc.getFullScreenWindow();

Compile the


Now create a class, which contains main(), within main() create an object of DisplayMode. See DisplayMode's constructor has four parameters, the first parameter is for width of the screen, the second is height, the third is color depth, and the last one is for refresh rate. Since I don't know the refresh rate, that's why I set it to REFRESH_RATE_UNKNOWN. Go through the comment and you will understand.

import java.awt.Color;
import java.awt.DisplayMode;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;

import javax.swing.JFrame;

public class EntryPoint extends JFrame{

	public static void main(String[] args) {
		DisplayMode dm=new DisplayMode(800, 600, 16, DisplayMode.REFRESH_RATE_UNKNOWN);
		EntryPoint b=new EntryPoint();;
public void run(DisplayMode dm){

      //set the background color of the frame to pink

      // set the Foreground color (for text) to green

      // set the font of the Text
    setFont(new Font("Arial", Font.PLAIN,27));

      //Create an Object of FullScreen class
    FullScreen fs=new FullScreen();

        //Call method setFullScreen to make the frame Full Screen
        fs.setFullScreen(dm, this);

         // Stay Full Screen for 5 sec.
        }catch(InterruptedException ex){}

        // after 5 sec. get out of the Full Screen
          //To draw a String on the Frame
	public void paint(Graphics g){
		if(g instanceof Graphics2D){
			Graphics2D g2=(Graphics2D)g;

            //Make the Text Smooth
		g.drawString("You Have Done", 200, 200);

Compile the


and run.

c:\>java EntryPoint

Download the attached file, unzip, compile and run.


  • 20th June, 2012: Initial post


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer
India India
No Biography provided

You may also be interested in...

Comments and Discussions

Questionreagarding Multiple JFRAMES Pin
Member 1030796330-Sep-13 19:53
memberMember 1030796330-Sep-13 19:53 
How to navigate from one FRAME to another FRAME by clicking next button. Actually the previous frame hidden backside, not closing. how to get rid of this. please post in this website

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170624.1 | Last Updated 21 Jun 2012
Article Copyright 2012 by Hassanoor
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid