Linux下运行JFrame程序,报java.lang.UnsupportedOperationException(当前系统不支持系统托盘),怎么解决

Linux下运行JFrame程序,报java.lang.UnsupportedOperationException(当前系统不支持系统托盘),怎么解决?
/**
* 托盘程序
*/
public ServiceTray() {
ti = new TrayIcon(ImageUtil.getBufferedImage("favicon.png"));
ti.setToolTip("智慧监管平台通讯软件");
ti.setImageAutoSize(true);

    try {
        // 添加托盘到系统托盘
        SystemTray.getSystemTray().add(ti);
        // 显示主页面
        sh = new ServiceHome();
        sh.setVisible(true);
        sh.start();
        // YdpDao.initYdpContent();
        // WinLog.write("[字模数据加载完成]", "成功");
    } catch (Exception e) {
        e.printStackTrace();
        return;
    }
    ActionListener al = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if ("退出".equals(e.getActionCommand())) {
                System.exit(0);
            } else if ("显示".equals(e.getActionCommand())) {
                if (null != sh) {
                    sh.setVisible(true);
                }
            } else if ("隐藏".equals(e.getActionCommand())) {
                if (null != sh) {
                    sh.setVisible(false);
                }
            }
        }
    };
    PopupMenu pm = new PopupMenu();
    MenuItem mi = new MenuItem("显示");
    pm.add(mi);
    mi.addActionListener(al);

    mi = new MenuItem("隐藏");
    pm.add(mi);
    mi.addActionListener(al);

    mi = new MenuItem("退出");
    pm.add(mi);
    mi.addActionListener(al);
    ti.setPopupMenu(pm);
    ti.addMouseListener(new MouseListener() {
        public void mouseClicked(MouseEvent e) {
            // 双击
            if (e.getClickCount() == 2) {
                if (null != sh) {
                    sh.setVisible(true);
                }
            }
        }

        public void mousePressed(MouseEvent e) {

        }

        public void mouseReleased(MouseEvent e) {

        }

        public void mouseEntered(MouseEvent e) {

        }

        public void mouseExited(MouseEvent e) {

        }
    });
}

 private TrayIcon()
      throws UnsupportedOperationException, HeadlessException, SecurityException
    {
        SystemTray.checkSystemTrayAllowed();
        if (GraphicsEnvironment.isHeadless()) {
            throw new HeadlessException();
        }
        if (!SystemTray.isSupported()) {
            throw new UnsupportedOperationException();
        }
        SunToolkit.insertTargetMapping(this, AppContext.getAppContext());
    }

在linux端运行jar文件,报错了。
图片说明

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐