SWT System Tray - Linux GTK Gnome Tray icons with “SWT” String on tray

孤街醉人 提交于 2019-12-07 14:24:53

问题


I am configuring the system tray icons with the following code:

/**
 * Configura os ícones da shell principal
 */
protected void setDiplayIcons(Shell shell){
    Display display = shell.getDisplay();
    InputStream inputImgTray = getClass().getClassLoader().getResourceAsStream(ImagensNaNOffline.IMG_LOGO_SEBRAE.getPath());
    Image image = new Image(display, inputImgTray);
    shell.setImage(image);

    Tray tray = display.getSystemTray();

    final ToolTip tip = new ToolTip(shell, SWT.BALLOON | SWT.ICON_INFORMATION);
    tip.setMessage("Balloon Message Goes Here!");
    if(tray != null) {
        TrayItem trayItem = new TrayItem(tray, SWT.NONE);
        trayItem.setImage(image);
        tip.setText("Balloon Title goes here.");
        trayItem.setToolTip(tip);
        final Menu menu = new Menu(shell, SWT.POP_UP);
        MenuItem menuItem = new MenuItem(menu, SWT.PUSH);
        menuItem.setText("Button A");
        menuItem = new MenuItem(menu, SWT.PUSH);
        menuItem.setText("Button B");
        menuItem = new MenuItem(menu, SWT.PUSH);
        menuItem.setText("Show Tooltip");
        menuItem.addListener (SWT.Selection, new Listener () {          
            public void handleEvent (Event e) {
                tip.setVisible(true);
            }
        });         
        trayItem.addListener (SWT.MenuDetect, new Listener () {
            public void handleEvent (Event event) {
                menu.setVisible (true);
            }
        });         
    }

}           

The tray are set OK but the STRING "SWT" is appearing in the side of Tray Icon as a label.

System is Fedora Core 17 (GNOME).

It is a platform issue or is there a way to change the text?

Here is a screenshot:


回答1:


You have a misconception about Gnome 3.x. The system tray is located on the bottom right corner and works fine with the supplied code example. So the "SWT" is located in your application title bar; the menu shown is the application menu with a quit menu item inserted by default.

Your screenshot shows the upper left corner of the desktop. "SWT" is a default fallback value of applications created with SWT. Whilst testing I was suprised that it doesn't correspond to the title of the (active) window. I suppose this is a bug. Technical details on how the application title is determined can be found in this question (Python and PyGTK; some external references): How to set application title in Gnome Shell?




回答2:


I managed to change the application name, thus the text I see in KDE's Systray, by using:

Display.setAppName("Whatever");

Just above all SWT code.



来源:https://stackoverflow.com/questions/14345450/swt-system-tray-linux-gtk-gnome-tray-icons-with-swt-string-on-tray

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!