Results 1 to 5 of 5
  1. #1
    olbion is offline Member
    Join Date
    May 2008
    Posts
    7
    Rep Power
    0

    Default [SOLVED] hyperlinks in JTextPane

    Hi,

    I have a java applet with a JTextPane component, to which text is added like this:
    <code>
    textPane = new JTextPane();
    doc = textPane.getStyledDocument();
    doc.insertString(doc.getLength(), message, doc.getStyle(style));
    </code>

    What I would like is to be able to add hyperlinks to this text, such that clicking one of them will bring up a separate browser window, in which one url or another will load. I know that the way to achieve the browser window is to use
    <code>
    getAppletContext().showDocument(userUrl,target)
    </code>

    What I don't know is how to connect a string added to the JTextPane to such a method. Is this at all possible? Or would I need to use components such as labels rather than strings to achieve it? The drawback that I see with such a solution is that it would not be possible to highlight/select text.

    Thank you very much for your help

  2. #2
    lonelyShoes is offline Member
    Join Date
    May 2008
    Posts
    6
    Rep Power
    0

    Default

    Have you seen the documentation on Sun's website about Editor Panes? If you are just asking how to mark up text inside the pane with HTML, then that article should answer your questions.

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  4. #4
    olbion is offline Member
    Join Date
    May 2008
    Posts
    7
    Rep Power
    0

    Default

    Thank you very much for pointing me in the right direction. With the JEditorPane and a HyperlinkListener, my problem was solved.

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. how to show a html document on JTextPane
    By mary in forum Advanced Java
    Replies: 2
    Last Post: 08-02-2007, 01:40 PM
  2. how to insert tables into JTextPane
    By osval in forum AWT / Swing
    Replies: 1
    Last Post: 07-29-2007, 09:11 AM
  3. hyperlinks from menu items?
    By asterope118 in forum New To Java
    Replies: 1
    Last Post: 07-16-2007, 01:49 PM
  4. Transparent JTextPane
    By Ada in forum AWT / Swing
    Replies: 1
    Last Post: 05-31-2007, 09:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •