1

我对 Gnome Shell 中显示的托盘项目有疑问。

项目图标出现在下栏中,我对此很好,就像其他图标一样,当将鼠标移到图标上时,会显示一个文本。

我的问题是无法更改此文本:设置文本.setText不起作用,该类都不支持任何事件,但是SelectedMenuDetect分别检测左键和右键单击。

有没有人遇到过同样的问题?

非常感谢您的回答,

詹卢卡

4

1 回答 1

0

不太确定您面临什么问题,但这对我有用:

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();
}

请注意,我不使用setText(),而是使用setToolTipText().

于 2012-09-12T22:15:35.037 回答