eclipse中shell窗口怎么居中显示

2025-03-13 14:55:23

1、在eclipse中新建一个swt-java项目,项目名字为javashell。

eclipse中shell窗口怎么居中显示

2、在项目中新建一个application window窗口。

eclipse中shell窗口怎么居中显示

3、运行项目,shell窗口在系统默认的位置显示出来,下一步让窗口居中显示。

eclipse中shell窗口怎么居中显示

4、找到createContents这个方法,得到屏幕的宽度。int width=shell.getDisplay().getBounds().width;

eclipse中shell窗口怎么居中显示

5、在这个方法中,得到屏幕的高度。int height=shell.getDisplay().getBounds().height;

eclipse中shell窗口怎么居中显示

6、得到屏幕的宽高度减去shell窗口的宽度和高度,除以2得到窗口的左上角坐标。int x=(width-shell.getBounds().width)/2; int y=(height-shell.getBounds().height)/2;

eclipse中shell窗口怎么居中显示

7、设置shell的左上角坐标, 运行项目,窗口居中显示。shell.setLocation(x, y);

eclipse中shell窗口怎么居中显示
声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢