灯火互联
管理员
管理员
  • 注册日期2011-07-27
  • 发帖数41778
  • QQ
  • 火币41290枚
  • 粉丝1086
  • 关注100
  • 终身成就奖
  • 最爱沙发
  • 忠实会员
  • 灌水天才奖
  • 贴图大师奖
  • 原创先锋奖
  • 特殊贡献奖
  • 宣传大使奖
  • 优秀斑竹奖
  • 社区明星
阅读:3099回复:0

java SWT /JFace窗口,剧中

楼主#
更多 发布于:2012-09-08 09:46

package com.ruifeng.swt.core;

import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

/**
* 布局UTIL
*
* @author lpdx111
*
*/
public class LayoutUtil {
    /**
     * Shell 布局,居中
     *
     * @param display
     * @param shell
     */
    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);
    }

    public static void centerShell(Shell shell) {
        Rectangle displayBounds = shell.getDisplay().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);
    }

    /**
     * jface dialog 根据窗口大小,获得居中的Point
     *
     * @param initialSize
     * @return
     */
    public static Point getLocation(Point initialSize) {
        Rectangle displayBounds = Display.getCurrent().getPrimaryMonitor()
                .getBounds();
        int x = displayBounds.x + (displayBounds.width - initialSize.x) >> 1;
        int y = displayBounds.y + (displayBounds.height - initialSize.y) >> 1;
        return new Point(x, y);
    }

}


摘自 lpdx111的专栏


喜欢0 评分0
游客

返回顶部