Sunday, July 26, 2015

How to make JFrame window Full Screen

Java provides getToolkit() method to get current environment details and then getScreentSize() of Toolkit class to get the current screen size. We can apply the size directly to the JFrame.

Solution 1

import javax.swing.*;
public class MyWindow extends JFrame
{
    public MyWindow()
    {
        setSize(getToolkit().getScreenSize());
        setVisible(true);
    }
    public static void main(String args[])
    {
        new MyWindow();
    }
}

Solution 2

import javax.swing.*;
import java.awt.*;
public class MyWindow extends JFrame 
{
    public MyWindow()
    {
        Toolkit t=getToolkit();
        Dimension d=t.getScreenSize();
        setSize(d);
        setVisible(true);
    }
    public static void main(String args[])
    {
        new MyWindow();
    }
}

No comments:

Post a Comment