How to get a SWT tray or TrayItem location

Any ideas on how to get the location of the tray (tray) or item on it (TrayItem) using SWT? Getting borders from the screen only gives me the whole screen. i.e

item.getDisplay().getBounds();

will provide me with (0, 0, 1024, 1024) in a windows window.

I would also like to know if the position of the system tray is (left, right, top, bottom), but you can probably guess, given the location. This is all so that I can display a message near the taskbar .

This is a duplicate of this post , but I want to offer generosity (and therefore control what I think is the right answer).

+5
source share
5 answers

Thanks to those who tried to answer. However, as in the case of another post , I think that it is simply impossible, so I answer my question in the negative: (

0
source

If you just want to display the shell near the tray element that responds to a user event (as in my case). You can get the location of the pointer when an event is fired over a tray item:

trayItem.addSelectionListener (new SelectionListener () {
    @Override public void widgetDefaultSelected (SelectionEvent aEvent) {
        widgetSelected (aEvent);
    }

    @Override public void widgetSelected (SelectionEvent aEvent) {
        if (mWindow.isVisible ()) {
            Shell wnd = mWindow;
            mWindow = new Shell (mDisplay);
            wnd.close ();
        }
        else {
            mWindow.setLocation (mDisplay.getCursorLocation ());
            mWindow.open ();
        }
    }
});

Here you can find all the source code here .

If you want to notify any other event (not generated by user input), I suggest that it’s best to use a tooltip, as Sandman points out in the previous answer.

Good luck !!!

+2
source

widget.getDisplay() , , .

Win32, MacOS, : - (

, , ...

MacOS - :

  • TrayItem ( checkSubClass())
  • getLocation(),

Win32 - - , messageProc(...). ...

+1

API, , ( , , ToolItem).: (

0

You can map one coordinate system to another using Display.map. You can map your element 0,0 (top left) in the coordinates of the screen by following these steps:

Display.map(item, null, 0, 0)

Use the null value as "to" for matching in the display coordinate space.

0
source

All Articles