Java无法加载URI

时间:2015-05-24 20:07:38

标签: java swing uri

我正在尝试添加指向JLabel的链接。我已将以下监听器添加到我的JLabel中:

   mouseAdapter = new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
                if (e.getClickCount() > 0) {
                    if (Desktop.isDesktopSupported()) {
                        Desktop desktop = Desktop.getDesktop();
                        try {
                            URI uri = new URI(path);
                            desktop.browse(uri);
                        } catch (Exception ex) {
                            LOGGER.error("Erorr when diplaying link for reports " + ex.getMessage());
                            JOptionPane.showMessageDialog(jpanel, "Eroare la afisarea raportului detaliat", "error",
                                    JOptionPane.ERROR_MESSAGE);
                        }
                    }
                }
            }
        };
        detailsLabel.addMouseListener(mouseAdapter);

但是当点击标签时会记录以下错误:

 Failed to show URI:/home/luci/workspace/LabMetrics/operations/target/detailedReport.html

我必须提到路径是一个有效的html页面。我正在使用Ubuntu 14.04,我安装了libgnome2.0-cil-dev,但它仍然无法正常工作。

1 个答案:

答案 0 :(得分:0)

我在路径之前添加了“file://”并且它正常工作。非常感谢!