Results 1 to 6 of 6
  1. #1
    sakray is offline Member
    Join Date
    Oct 2013
    Posts
    5
    Rep Power
    0

    Unhappy Clickable links in a JTextPane?

    Hi guys, I'm creating a text editor in JAVA and use the JTextPane to input the text. My problem is that I need to be able to input references that are clickable and want to avoid the usage of HTML. I created an object for each reference with the following information:
    ------
    Title:
    Description:
    PathToFile:
    -----
    I want to display the title in the text as clickable but have no idea how to proceed? action listener ? mouse listener? ideas?

    Thanks

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,815
    Rep Power
    25

    Default Re: Clickable links in a JTextPane?

    want to avoid the usage of HTML
    Why? Can you explain?
    Do you want to write your own code to recognize where the click was made and to correlate that with some action.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    sakray is offline Member
    Join Date
    Oct 2013
    Posts
    5
    Rep Power
    0

    Default Re: Clickable links in a JTextPane?

    Quote Originally Posted by Norm View Post
    Why? Can you explain?
    Do you want to write your own code to recognize where the click was made and to correlate that with some action.
    Exactly, if there is no better way. The text editor will be used by reporters who want to have a lot of "references" to different files on the computer ex.

    According to this file, the boy was shot in the head.

    This magazine from 1990 shows that the suspect was innocent.

    I was thinking abt doing JLables and listen for clicks on them, but dont know if that would work in a JTextArea. Every "reference" needs to be unique and have the information stated above in its object.

    Any ideas?

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,182
    Rep Power
    20

    Default Re: Clickable links in a JTextPane?

    Look at JEditorPane or (probably) JTextPane, which is a subclass.
    That handles hyperlinks, which is what you seem to be wanting, and you can attach a listener on those links.

    I've not done it, so can't really help.
    Here's the text component tutorial.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    sakray is offline Member
    Join Date
    Oct 2013
    Posts
    5
    Rep Power
    0

    Default Re: Clickable links in a JTextPane?

    Quote Originally Posted by Tolls View Post
    Look at JEditorPane or (probably) JTextPane, which is a subclass.
    That handles hyperlinks, which is what you seem to be wanting, and you can attach a listener on those links.

    I've not done it, so can't really help.
    Here's the text component tutorial.
    Thanks, but that does not solve my problem because the links can't be clickable at the same time as the JTextPane is editable.

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,182
    Rep Power
    20

    Default Re: Clickable links in a JTextPane?

    ?
    Not sure what you mean.
    You need to define exactly what it is you want, because it sounded like you simply wanted a way for people click on links.
    If you want something to be clickable when someone is entering data then you'll need to describe how you expect the user to identify which bits of the stuff they're writing is something to be turned into a link.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Replies: 1
    Last Post: 08-24-2013, 07:22 PM
  2. JButton not clickable
    By StevenTNorris in forum AWT / Swing
    Replies: 5
    Last Post: 11-09-2012, 09:59 PM
  3. Clickable image
    By xtre in forum New To Java
    Replies: 2
    Last Post: 09-08-2012, 02:56 PM
  4. Clickable text in a component
    By kjkrum in forum AWT / Swing
    Replies: 3
    Last Post: 11-06-2011, 12:25 AM
  5. Double Clickable Application
    By ellias2007 in forum Advanced Java
    Replies: 7
    Last Post: 03-08-2010, 05:08 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
  •