囝泺的博客[www.bluenuo.cn]

网盘[disk.bluenuo.cn]
随笔 - 6, 文章 - 0, 评论 - 6, 引用 - 0
数据加载中……

2007年12月16日

主窗口居中显示

文/囝泺 www.bluenuo.cn

 

shell = new Shell();
shell.setSize(
500375);
    Monitor primary = shell.getMonitor();//获得屏幕
    Rectangle bounds 
= primary.getBounds ();//获得屏幕尺寸
    Rectangle rect 
= shell.getBounds ();//获得窗口尺寸
    
int x = bounds.x + (bounds.width - rect.width) / 2;//计算x坐标
    
int y = bounds.y + (bounds.height - rect.height) / 2;//计算y坐标
    
if (x < 0)//判断坐标是否在屏幕之外
        x 
= 0;
        
if (y < 0)
            y 
= 0;
        shell.setLocation (x, y);//设置窗口坐标
    shell.open();

posted @ 2007-12-16 15:35 囝泺 阅读(103) | 评论 (0)编辑 收藏