SWT编写界面窗口时让窗口处于屏幕中间
来源:互联网 发布:安卓应用推荐 知乎 编辑:程序博客网 时间:2024/05/17 21:17
一、使用SWT本身
import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; public class LayoutUtil ...{ public static void centerShell(Display display,Shell shell)...{ Rectangle displayBounds = display.getPrimaryMonitor().getBounds(); Rectangle shellBounds = shell.getBounds(); int x = displayBounds.x + (displayBounds.width - shellBounds.width)>>1; int y = displayBounds.y + (displayBounds.height - shellBounds.height)>>1; shell.setLocation(x, y); } }
直接调用LayoutUtil.centerShell(Display display,Shell shell)即可使SWT窗口处于屏幕中央,其中,shell 要显示的Shell对象。
二、借助AWT包里面获取屏幕大小的方法
import java.awt.Toolkit; /** *//** * 在屏幕中间显示Shell * @param shell 要显示的Shell对象 */ private void centerShell(Shell shell) ...{ //得到屏幕的宽度和高度 int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height; int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width; //得到Shell窗口的宽度和高度 int shellHeight = shell.getBounds().height; int shellWidth = shell.getBounds().width; //如果窗口大小超过屏幕大小,让窗口与屏幕等大 if(shellHeight > screenHeight) shellHeight = screenHeight; if(shellWidth > screenWidth) shellWidth = screenWidth; //让窗口在屏幕中间显示 shell.setLocation(( (screenWidth - shellWidth) / 2),((screenHeight - shellHeight) / 2) ); }
0 0
- SWT编写界面窗口时让窗口处于屏幕中间
- SWT编写界面窗口时让窗口处于屏幕中间
- SWT编写界面窗口时让窗口处于屏幕中间
- SWT编写界面窗口时让窗口处于屏幕中间
- SWT编写界面窗口时让窗口处于屏幕中间
- SWT编写界面窗口时让窗口处于屏幕中间
- SWT/JFace设置窗口位于屏幕中间
- 将swt窗口居中(屏幕中间)将swing窗口居中
- 聊天窗口界面编写
- 让子窗口和父窗口同时处于"激活状态"
- Java 使窗口位于屏幕中间
- 让弹出窗口在屏幕中间显示,没有滚动条,并且点击某行,窗口大小不变化.
- MFC使窗口弹出时显示在屏幕中间或屏幕左上角
- 将exe窗口嵌入java的swt界面中
- Swing中如何将窗口显示在屏幕正中间
- Qt编程之窗口居屏幕中间显示
- PyQt5:将窗口放在屏幕中间(6)
- 如何让一个VB窗口总是处于各窗口的最上层
- C++Primer3.3.3节练习题。
- Session应用之---防止表单重复提交
- 二分查找法
- ubuntu安装ftp服务器
- C++ 异或运算
- SWT编写界面窗口时让窗口处于屏幕中间
- 高仿新闻教程--新闻Item的布局复习(3)
- 使用回调方式写POI导入excel工具类
- Program work 4. Infix expression convert to Prefix expression (Ⅰ)
- 使用回调方式写POI导入excel工具类
- STL提供了三个最基本的容器:vector,list,deque
- Topcoder Single Round Match 453.5 Round 1 - Division I, Level Two TheProduct
- 使用回调方式写POI导入excel工具类
- 在真机上调试Android应用程序(图文详解)