import java.awt.Dimension; import java.awt.GraphicsEnvironment; import java.awt.Insets; import java.awt.Rectangle; import java.awt.Toolkit; Rectangle windowSize = new Rectangle(); Dimension scrSize = Toolkit.getDefaultToolkit().getScreenSize(); Insets scrInsets = Toolkit.getDefaultToolkit().getScreenInsets(GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration()); //获取屏幕可以利用的width和height //windowSize.setBounds(scrInsets.left, scrInsets.top, scrSize.width - scrInsets.left - scrInsets.right, scrSize.height - scrInsets.top - scrInsets.bottom); //获取屏幕的分辨率 windowSize.setBounds(scrInsets.left, scrInsets.top, scrSize.width, scrSize.height); logger.info("The window size is : "+windowSize);
输出结果:
The window size is : java.awt.Rectangle[x=0,y=0,width=1280,height=1024]