How to make Shell always be on top in SWT?

I want the option “Always on top” to be implemented in my application, which takes effect immediately.

I know that I can call a constructor Shellwith a style ON_TOP. Is there a way to do this at runtime, that is, after the instance is Shellalready created?

+3
source share
4 answers

In Cocoa, you need to use reflection to get the shell instance variable windowand then call window.setLevel(OS.NSStatusWindowLevel).

Carbon shellHandle, OS.SetWindowGroup(shellHandle, OS.kFloatingWindowClass). , , .

SWT.ON_TOP style. , Carbon , .

+3

:

private static final void toggleAlwaysOnTop(Shell shell, boolean isOnTop){
    long handle = shell.handle;
    Point location = shell.getLocation();
    Point dimension = shell.getSize();
    OS.SetWindowPos(handle, isOnTop ? OS.HWND_TOPMOST : OS.HWND_NOTOPMOST,location.x, location.y, dimension.x, dimension.y, 0);
}

api , .

SetWindowPos Shell.getStyle(). 0, .

+3

There is no standard way to change widget styles after they are created.

You should check what code will be executed at creation time, and then call the native native method (in the class OS).

Download the SWT source for your platform to find out how it works. This is not magic, just a little manual debugging.

+1
source

Source: https://habr.com/ru/post/1744738/


All Articles