养生 装修 购物 美食 感冒 便秘 营销 加盟 小吃 火锅 管理 创业 搭配 减肥 培训 旅游

eclipse中shell窗口怎么居中显示

时间:2024-09-28 23:29:03

swt-java中shell窗口怎么居中饺咛百柘显示呢,利用setLocation设置窗口左上角坐标使shell窗口居中。我和大家分享棒瀹跏癞一下居中显示的方法,我写的经验对你学习java有帮助的话,给我投票、点赞或者收藏!

工具/原料

eclipse

方法/步骤

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

eclipse中shell窗口怎么居中显示

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

eclipse中shell窗口怎么居中显示

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

eclipse中shell窗口怎么居中显示

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

eclipse中shell窗口怎么居中显示

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

eclipse中shell窗口怎么居中显示

6、得到屏幕的宽高度减去shell窗口的宽度和高度,除以2得到窗口的左上角坐标。in隋茚粟胫tx=(width-shell.getBounds().臃扮哀坷width)/2; inty=(height-shell.getBounds().height)/2;

eclipse中shell窗口怎么居中显示

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

eclipse中shell窗口怎么居中显示

© 一点知识