`
liugang594
  • 浏览: 981209 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

置窗口于显示器中央

阅读更多

要把窗口置于显示器的中央,也是很容易的。如下:

 

	                private static final int WIDTH = 200;
	                private static final int HEIGHT = 100;


                                Monitor monitor = shell.getMonitor();
		Rectangle bounds = monitor.getBounds();
		int x = (bounds.width-WIDTH)/2;
		int y = (bounds.height-HEIGHT)/2;
		shell.setLocation(new Point(x,y));

 

 在shell中有一个getMonitor()方法,可以得到当前shell所在的monitor,然后通过计算monitor的大小和shell的大小来得到中央位置。最后设置

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics