行者K 2019-03-26 17:25 采纳率: 0%
浏览 739

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文件,报错了。
图片说明

  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥100 Jenkins自动化部署—悬赏100元
    • ¥15 关于#python#的问题:求帮写python代码
    • ¥20 MATLAB画图图形出现上下震荡的线条
    • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
    • ¥15 perl MISA分析p3_in脚本出错
    • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
    • ¥15 ubuntu虚拟机打包apk错误
    • ¥199 rust编程架构设计的方案 有偿
    • ¥15 回答4f系统的像差计算
    • ¥15 java如何提取出pdf里的文字?