1

JEdi​​torPane でハイパーリンクを機能させるのに苦労しています。誰かが私がここで間違っていることを教えてもらえますか? リンクとブラウザをクリックしてそのページを開くことができるようにしたい。前もって感謝します。:D

    bottomText.setText("<a href=\"http://www.yahoo.com\">Yahoo</a>");
    bottomText.setEditable(false);
    bottomText.setOpaque(false);
    bottomText.setEditorKit(JEditorPane.createEditorKitForContentType("text/html"));
    bottomText.addHyperlinkListener(new HyperlinkListener() {
        public void hyperlinkUpdate(HyperlinkEvent e) {
            if(e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {

            }
            if(Desktop.isDesktopSupported()) {
                try {
                    Desktop.getDesktop().browse(e.getURL().toURI());
                } catch (IOException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                } catch (URISyntaxException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }
            }

        }

    });
4

2 に答える 2

3

bottomText.setEditorKit前に電話するbottomText.setText

于 2012-08-01T05:52:33.797 に答える
3

うわー、それは私よりも簡単でした:P

// Move this
//bottomText.setText("<a href=\"http://www.yahoo.com\">Yahoo</a>");
bottomText.setEditable(false);
bottomText.setOpaque(false);
bottomText.setEditorKit(JEditorPane.createEditorKitForContentType("text/html"))
// To Here
bottomText.setText("<a href=\"http://www.yahoo.com\">Yahoo</a>");

ああ、ブラウザを開く前にユーザーがリンクをクリックするまで待ってください。例を殺す前に約4つのウィンドウがありました;)

クリックでUPDATE

あなたはほとんどそこにいました;)

bottomText.addHyperlinkListener(new HyperlinkListener() {
    public void hyperlinkUpdate(HyperlinkEvent e) {
        if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
            if (Desktop.isDesktopSupported()) {
                try {
                    Desktop.getDesktop().browse(e.getURL().toURI());
                } catch (IOException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                } catch (URISyntaxException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }
            }
        }
    }
});
于 2012-08-01T05:48:17.550 に答える