Java 将浏览器外壳移动到右上角

Java 将浏览器外壳移动到右上角,java,swt,Java,Swt,使用java,我创建了一个shell,然后在shell中打开浏览器,我想将shell移动到屏幕的右上角。我正在尝试使用setBound函数,但它不起作用。。如何找到右上方屏幕的坐标。 如何将外壳设置到特定位置 代码: 您可以通过获取以下内容的边界来找到屏幕的右上角: 如果要考虑多个监视器,可以使用并实现一些逻辑来选择所关心的监视器 您在正确的轨道上定位Shell。您可以使用上方的topRight点,减去外壳的宽度,使其保持在屏幕上。或者,您可以使用一种方法 例如: public class Sh

使用java,我创建了一个shell,然后在shell中打开浏览器,我想将shell移动到屏幕的右上角。我正在尝试使用setBound函数,但它不起作用。。如何找到右上方屏幕的坐标。 如何将外壳设置到特定位置 代码:


您可以通过获取以下内容的边界来找到屏幕的右上角:

如果要考虑多个监视器,可以使用并实现一些逻辑来选择所关心的
监视器

您在正确的轨道上定位
Shell
。您可以使用上方的
topRight
,减去
外壳的宽度
,使其保持在屏幕上。或者,您可以使用一种方法

例如:

public class ShellLocationTest {

    private final Display display;
    private final Shell shell;

    public ShellLocationTest() {
        display = new Display();
        shell = new Shell(display, SWT.NONE);
        final Point shellSize = new Point(400, 200);
        shell.setSize(shellSize);
        shell.setLayout(new FillLayout());

        final Rectangle monitorBounds = display.getPrimaryMonitor().getBounds();
        final Point shellLocation = new Point(monitorBounds.x + monitorBounds.width - shellSize.x, monitorBounds.y);
        shell.setLocation(shellLocation);
    }

    public void run() {
        shell.open();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch()) {
                display.sleep();
            }
        }
        display.dispose();
    }

    public static void main(String... args) {
        new ShellLocationTest().run();
    }

}
final Monitor monitor = Display.getCurrent().getPrimaryMonitor();
final Rectangle monitorBounds = monitor.getBounds();
final Point topRight = new Point(monitorBounds.x + monitorBounds.width, monitorBounds.y);
public class ShellLocationTest {

    private final Display display;
    private final Shell shell;

    public ShellLocationTest() {
        display = new Display();
        shell = new Shell(display, SWT.NONE);
        final Point shellSize = new Point(400, 200);
        shell.setSize(shellSize);
        shell.setLayout(new FillLayout());

        final Rectangle monitorBounds = display.getPrimaryMonitor().getBounds();
        final Point shellLocation = new Point(monitorBounds.x + monitorBounds.width - shellSize.x, monitorBounds.y);
        shell.setLocation(shellLocation);
    }

    public void run() {
        shell.open();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch()) {
                display.sleep();
            }
        }
        display.dispose();
    }

    public static void main(String... args) {
        new ShellLocationTest().run();
    }

}