Ariyan
Ariyan

Reputation: 15158

Displaying custom String as link in JEditorPane

How can I show a custom string like [1234|alink] as link with "alink" as text and "1234" as its location without replacing it with a <a> tag?
I mean something like a BBCode.

Upvotes: 2

Views: 209

Answers (1)

Guillaume Polet
Guillaume Polet

Reputation: 47617

I see several options here:

  1. You pre-process your strings and convert your tags to equivalent HTML
  2. You start playing with parsers/DTD/EditorKit.

    a. You create your own syntax (could be time-consuming)

    b. You reuse the HTMLEditorKit (you need to extend it), try to add more information to the default DTD to add your custom elements (and therefore make the Parser return your additional elements) and you extend the ViewFactory so that you can render your new elements with dedicated views.

While option 2. is clearly better in the long run (and particularly if you are really interested in high performance), option 1. is really easy to implement.

See these links for more info:

Upvotes: 2

Related Questions