简体   繁体   English

程序启动时未显示系统任务栏图标

[英]system tray icon not displaying on startup of program

I used following code for display system tray icon and message. 我将以下代码用于显示系统任务栏图标和消息。 Startup message and tooltip message is displayed well. 启动消息和工具提示消息显示良好。 But tray icon is not displaying. 但是托盘图标未显示。 The icon is in images folder. 该图标在图像文件夹中。 How can i solve this problem ? 我怎么解决这个问题 ?

    public void systemTray() {
    try {
        SystemTray tray = SystemTray.getSystemTray();
        ImageIcon icon=new ImageIcon(getClass().getResource("/images/Reg Member MO.png"));
        Image image = icon.getImage();
        TrayIcon icn = new TrayIcon(image, "This is demonstration system tray");
        icn.setToolTip("Now you can see system tray\ntooltip here\nThis is demonstration system tray ToolTip");
        tray.add(icn);     
        icn.displayMessage("This is demonstration System Tray message", "You can add some text to\ndisplay here as System Tray Message", TrayIcon.MessageType.INFO);
    } catch (AWTException ex) {
        Logger.getLogger(StartupSystemTray.class.getName()).log(Level.SEVERE, null, ex);
    }
}

May be your icon image is too large than allocated space. 可能是您的图标图片太大,无法分配空间。 Try using public void setImageAutoSize(boolean autosize) method as icn.setImageAutoSize(true) . 尝试使用public void setImageAutoSize(boolean autosize) icn.setImageAutoSize(true) public void setImageAutoSize(boolean autosize)方法作为icn.setImageAutoSize(true) This will re-size the image. 这将调整图像大小。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM