문제

Is there a way to remove SWT Shell border and also support window re-positioning. I used SWT.NONE in my Shell style to remove the window border but it also ended up in locking the UI position.

도움이 되었습니까?

해결책

Yes you can, but you have to handle drag events yourself. Here is an example:

public static void main(String[] args)
{
    final Display display = new Display();
    final Shell shell = new Shell(display, SWT.NO_TRIM | SWT.ON_TOP);

    Listener l = new Listener()
    {
        Point origin;

        public void handleEvent(Event e)
        {
            switch (e.type)
            {
                case SWT.MouseDown:
                    origin = new Point(e.x, e.y);
                    break;
                case SWT.MouseUp:
                    origin = null;
                    break;
                case SWT.MouseMove:
                    if (origin != null)
                    {
                        Point p = display.map(shell, null, e.x, e.y);
                        shell.setLocation(p.x - origin.x, p.y - origin.y);
                    }
                    break;
            }
        }
    };
    shell.addListener(SWT.MouseDown, l);
    shell.addListener(SWT.MouseUp, l);
    shell.addListener(SWT.MouseMove, l);

    shell.setSize(400, 300);
    shell.open();

    while (!shell.isDisposed())
    {
        if (!display.readAndDispatch())
        {
            display.sleep();
        }
    }
    display.dispose();
}

It's not really worth posting a screenshot, since it's just a draggable grey window.

Update

If you want the whole Shell to be draggable even if it contains other widgets, then use this instead:

    display.addFilter(SWT.MouseDown, l);
    display.addFilter(SWT.MouseUp, l);
    display.addFilter(SWT.MouseMove, l);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top