Swing JDialog / JTextPane和HTML链接 [英] Swing JDialog/JTextPane and HTML links

查看:237
本文介绍了Swing JDialog / JTextPane和HTML链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个JDialog中使用一个swing页面内的 css> JTextPane 。
在html中我有一个< ; a href =mailto:email@adress.com> John< / a>

当鼠标移动到链接时,通过资源管理器查看网页我可以看到 mailto

当我按链接时,出现错误没有安装默认邮件客户端,但我想这是由于在我的PC中,我还没有配置Outlook或其他程序。

当我从Swing应用程序打开JDialog时,我看到 John 突出显示为链接,但是当我按链接时什么也没有发生。

我期望得到与浏览器相同的错误信息。

所以我的问题是可以通过Swing应用程序打开链接或不?

I am using an html page inside a swing JTextPane in a JDialog.
In the html I have a <a href="mailto:email@adress.com">John</a>
When I view the web page via an explorer when the mouse goes to the link I can see the mailto.
When I press the link I get the error "no default mail client installed", but I guess this is due to in my PC I have not configured Outlook or some other program.
When I open the JDialog from my Swing application, I see John highlighted as a link, but when I press the link nothing happens.
I was expecting to get the same error message as the browser.
So my question is can the link be opened via a Swing application or not?

谢谢

Thanks

推荐答案

无论是工具提示(显示目标超链接地址),也不会按下按钮上的动作,您必须对其进行编码:首先,使用ToolTipManager注册窗格,为后者注册HyperlinkListener,如下所示:

Neither the tooltip (showing the target hyperlink address) nor the action on press happens automatically, you have to code it: for the first, register the pane with the ToolTipManager, for the latter, register a HyperlinkListener, something like:

    final JEditorPane pane = new JEditorPane("http://swingx.java.net");
    pane.setEditable(false);
    ToolTipManager.sharedInstance().registerComponent(pane);

    HyperlinkListener l = new HyperlinkListener() {
        @Override
        public void hyperlinkUpdate(HyperlinkEvent e) {
            if (HyperlinkEvent.EventType.ACTIVATED == e.getEventType()) {
                try {
                    pane.setPage(e.getURL());
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            }

        }

    };
    pane.addHyperlinkListener(l);

这个例子是关于在同一窗格中打开页面的。如果你想激活默认的浏览器/邮件客户端,请问桌面(jdk1.6的新手)为你做这件事。

The example is about opening the page in the same pane. If you want to activate the default browser/mail-client, ask the Desktop (new to jdk1.6) to do it for you

这篇关于Swing JDialog / JTextPane和HTML链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆