SWT - 在屏幕右侧显示快照

时间:2013-05-06 03:50:09

标签: java swt

我正在创建一个SWT应用程序并且在网上搜索没有成功的方法将我的窗口捕捉到屏幕右侧(与谷歌桌面用来工作的方式类似)。

因此,如果开始菜单位于屏幕的右侧,则它应位于屏幕的左侧,否则它可以直接捕捉到屏幕的右侧。

任何人都可以帮我解决这个问题吗?

2 个答案:

答案 0 :(得分:3)

使用以下方法在主shell上设置边界。

org.eclipse.swt.widgets.Display

public Monitor [] getMonitors ()

public Monitor getPrimaryMonitor ()

答案 1 :(得分:1)

以下是一些利用sambi找到的函数的代码:

public static void main(String[] args)
{
    Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setLayout(new FillLayout(SWT.VERTICAL));
    shell.setText("StackOverflow");

    Monitor primary = display.getPrimaryMonitor();

        /* Get the available screen size (without start menu) */
    Rectangle area = primary.getClientArea();

    shell.pack();
    /* Set the shell size */
    shell.setBounds(area.x + area.width / 2, area.y, area.width / 2, area.height);
    shell.open();
    while (!shell.isDisposed())
    {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

在Linux(面板左下角)和Windows 7(左侧开始菜单)上进行测试。