Java eclipse中shell窗口怎么居中显示

 

protected void createContents() {
        shell = new Shell();
        shell.setSize(800, 600);
        shell.setText(title);

        int width=shell.getDisplay().getBounds().width;  // 找到createContents这个方法,得到屏幕的宽度。
        int height=shell.getDisplay().getBounds().height;  // 在这个方法中,得到屏幕的高度。
        // 得到屏幕的宽高度减去shell窗口的宽度和高度,除以2得到窗口的左上角坐标。
        int x=(width-shell.getBounds().width)/2;
        int y=(height-shell.getBounds().height)/2;
        shell.setLocation(x, y);

}

 

posted @ 2020-07-19 17:58  emanlee  阅读(470)  评论(0编辑  收藏  举报