eclipse中shell窗口怎么居中显示

时间:2024-10-12 19:15: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窗口怎么居中显示
© 2025 光影知识库
信息来自网络 所有数据仅供参考
有疑问请联系站长 site.kefu@gmail.com