Jad J
Jad J

Reputation: 91

getMaximumSize() for dual screen

if you have a dual screen computer, how do I make my program open to fill the screen just on my main monitor? If I use the getMaximumSize() method, it extends to my second screen?

frame.setSize(frame.getMaximumSize()); 

Upvotes: 0

Views: 237

Answers (2)

Captain Charmi
Captain Charmi

Reputation: 604

You can get the size from the graphics configuration.

import java.awt.GraphicsConfiguration;  
import java.awt.GraphicsDevice;  
import java.awt.GraphicsEnvironment;  

public class GuiScreens {  
    public static void main(String[] args) {  
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();  
        GraphicsDevice[] gs = ge.getScreenDevices();  
        GraphicsConfiguration[] gc = gs[0].getConfigurations();  
        System.out.println("    Bounds: " + gc[0].getBounds());  
   }  
}  

Upvotes: 3

Robin
Robin

Reputation: 36611

You can use Toolkit#getScreenSize() to determine the screen size, and set the frame to that size

Upvotes: 2

Related Questions