1

I'm creating an app in Java that needs to fulfill all the monitor screen.

I'm using .setExtendedState(MAXIMIZED_BOTH) but it only fulfill the workspace.

        JFrame frame = new JFrame("Pomodoro");
        frame.setContentPane(new Pomodoro().panel);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setVisible(true);
        frame.setExtendedState(MAXIMIZED_BOTH);
        frame.setUndecorated(true);
     }

I expect the app to take all the monitor screen - like youtube videos. Now, when I open the app it has my Linux menu on the right and on the top, but when I move my app to the second monitor it fulfills all monitor screen.

wloszynski
  • 37
  • 6
  • Did you run a search ? See [this](https://stackoverflow.com/questions/11570356/jframe-in-full-screen-java) question. – c0der Aug 29 '19 at 15:50

1 Answers1

1

While this should normally be enough to show a fullscreen window (methods order is important!):

public class FullscreenWindow
{
    public static void main ( final String[] args )
    {
        SwingUtilities.invokeLater ( new Runnable ()
        {
            @Override
            public void run ()
            {
                final JFrame frame = new JFrame ();
                frame.setExtendedState ( JFrame.MAXIMIZED_BOTH );
                frame.setUndecorated ( true );
                frame.setVisible ( true );
            }
        } );
    }
}

It is not enough to make your system recognize that window as a truly fullscreen. Whether you need that or not is up to you though since truly fullscreen window has it's own pros and cons.

To make any Window an actual fullscreen window in your system - you need to pass it into graphics device like this:

public class FullscreenWindow
{
    public static void main ( final String[] args )
    {
        SwingUtilities.invokeLater ( new Runnable ()
        {
            @Override
            public void run ()
            {
                final JFrame frame = new JFrame ();
                frame.setExtendedState ( JFrame.MAXIMIZED_BOTH );
                frame.setUndecorated ( true );
                frame.setVisible ( true );
                frame.getGraphicsConfiguration ().getDevice ().setFullScreenWindow ( frame );
            }
        } );
    }
}

Graphics device basically represents a single screen device you have attached to your PC, obviously there could be more than one.

While the example above will only make your window fullscreen on it's current graphics device (screen that window is mostly placed on), you can make your window fullscreen on any other available graphic device as well.

You can retrieve full list of available graphics devices like this:

GraphicsDevice[] screenDevices = GraphicsEnvironment.getLocalGraphicsEnvironment ().getScreenDevices ();

You can also request actual sizes from the graphics devices and their relative locations to each other to better understand how user's screens are positioned (configured in system settings) relative to each other.

Mikle Garin
  • 10,083
  • 37
  • 59