1

I have an issue about the tray items display in Gnome Shell.

The item icon appears in the lower bar, and I'm fine with that, and just like the other ones, when moving the mouse over the icon, a text is displayed.

My problem is that this text cannot be changed: setting a text with .setText does not work, neither the class support any event, but Selected and MenuDetect, which detect the left and right click, respectively.

Has anybody experienced the same problem?

Thanks a lot in advance for your answers,

Gianluca

Baz
  • 36,440
  • 11
  • 68
  • 94
kekolab
  • 801
  • 10
  • 24

1 Answers1

0

Not quite sure what problem you are facing, but this works for me:

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());

    final Tray tray = display.getSystemTray();
    TrayItem item;
    if (tray != null) {
        item = new TrayItem(tray, SWT.NONE);
        item.setToolTipText("A");
        item.setImage(display.getSystemImage(SWT.ICON_ERROR));
    }

    Button button = new Button(shell, SWT.PUSH);
    button.setText("Change tray text");

    button.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event arg0) {

            if(tray != null)
            {
                TrayItem item = tray.getItem(0);
                item.setToolTipText(item.getToolTipText() + "A");
            }

        }
    });

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

Note that I don't use setText(), but rather setToolTipText().

Baz
  • 36,440
  • 11
  • 68
  • 94
  • Thanks for your answer, Baz, but the problem is still there.

    Have a look at this image: http://imageshack.us/photo/my-images/507/schermatadel20120914120.png/
    As you can see, when the mouse is on an icon, the icon shifts towards left and the program's name appears. When I do it on my tray item, what appears, is "SWT". I was trying to find a way to make a custom string appear... The tooltip text seems not to be connected to it. In addition, the tooltip "baloon" doesn't appear either when hovering with the mouse, but I had already read of that behaviour.

    Thanks again for your support.

    – kekolab Sep 14 '12 at 10:36
  • @Gianluca Did you run the code snippet I provided by itself or did you integrate it into your code? If it's the second, please try the snippet by itself and report back. – Baz Sep 14 '12 at 10:41
  • yes... and [here](http://imageshack.us/photo/my-images/525/screenshotfrom201209161.png/) you have the result. As you can see, the text on the side of the icon is still "SWT", although the balloon text does change after pushing the button. No clue about how to set that text? Maybe it is impossible with SWT? – kekolab Sep 16 '12 at 12:38
  • @Gianluca Ok, I found [this](http://stackoverflow.com/questions/9324163/how-to-set-application-title-in-gnome-shell) where someone has the same problem in python. So the problem seems to be originated in the gnome-shell code. When there is no instance your program can be mapped to, it will just use "SWT". Maybe it will help to create a .desktop file as described in the answer to that question. Hope it helps... – Baz Sep 16 '12 at 13:16