swing中设置JFrame的大小占满屏幕

JFrame parentFrame=new JFrame();
Dimension screenSize=Toolkit.getDefaultToolkit().getScreenSize();
Insets screenInsets=Toolkit.getDefaultToolkit().getScreenInsets(parentFrame.getGraphicsConfiguration());
final Rectangle frameBounds=new Rectangle(
					screenInsets.left, screenInsets.top, 
						screenSize.width-screenInsets.left-screenInsets.right, 
							screenSize.height-screenInsets.top-screenInsets.bottom);
						
//sets the bounds of the main frame
parentFrame.setBounds(frameBounds);
 

你可能感兴趣的