SWT - 将显示捕捉到屏幕的右侧 [英] SWT - Snap display to right hand side of the screen

查看:38
本文介绍了SWT - 将显示捕捉到屏幕的右侧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个 SWT 应用程序,但一直没有成功在网上搜索将我的窗口捕捉到屏幕右侧的方法(以类似于谷歌桌面过去的工作方式).

I'm creating an SWT application and have been unsuccessfully searching around on the net for a way to snap my window to the right of the screen (in a similar fashion to the way google desktop used to work).

因此,如果开始菜单位于屏幕的右侧,则它应该位于左侧,否则它会直接吸附到屏幕的右侧.

So if the start menu is on the right hand side of the screen it should sit to the left of it otherwise it can snap directly to the right hand side of the screen.

谁能帮我解决这个问题?

Can anyone help me out with a way that I can do this?

推荐答案

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

Here is some code that utilizes the functions found by 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(开始菜单左侧)上测试.

Tested on both Linux (panel left and bottom) and Windows 7 (start menu left).

这篇关于SWT - 将显示捕捉到屏幕的右侧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆