I have a JTable
which uses JTextPane
as editor and renderer. I added a keyListener to the editor, that listens for "space" character and checks if the last word is URL and if it is, adds it to the editor as a hyperlink using this attribute: attrs.addAttribute(HTML.Attribute.HREF, url);
. I soon figured that this won't convert URLs to hyperlinks when I paste text so I decided I need to do this using DocumentFilter
.
How can I create a DocumentFilter
that checks if the text about to be inserted/replaced contains URLs and if it does inserts/replaces thoose URLs with the HTML.Attribute.HREF
attribute and the rest of the text as it is?