swt-java中shell窗口怎么居中饺咛百柘显示呢,利用setLocation设置窗口左上角坐标使shell窗口居中。我和大家分享棒瀹跏癞一下居中显示的方法,我写的经验对你学习java有帮助的话,给我投票、点赞或者收藏!
工具/原料
eclipse
方法/步骤
1、在eclipse中新建一个swt-java项目,项目名字为javashell。
2、在项目中新建一个applicationwindow窗口。
3、运行项目,shell窗口在系统默认的位置显示出来,下一步让窗口居中显示。
4、找到createContents这个方法,得到屏幕的宽度。intwidth=shell.getDisplay().getBounds().width;
5、在这个方法中,得到屏幕的高度。intheight=shell.getDisplay().getBounds().height;
6、得到屏幕的宽高度减去shell窗口的宽度和高度,除以2得到窗口的左上角坐标。in隋茚粟胫tx=(width-shell.getBounds().臃扮哀坷width)/2; inty=(height-shell.getBounds().height)/2;
7、设置shell的左上角坐标,运行项目,窗口居中显示。shell.setLocation(x,y);